angular/packages/zone.js/test/node/Error.spec.ts
Kristiyan Kostadinov 41223a81f2 build: update to jasmine 4.0 (#45558)
Updates us to version 4.0 of Jasmine and fixes some errors that were the result of us depending upon deprecated APIs. We need to do this both to stay up to date and because it was going to break eventually, because one of the Bazel packages was logging a deprecation warning that version 4.0 was required.

There were also some cases where the state of `ngDevMode` had started leaking out between tests.

PR Close #45558
2022-04-11 16:25:28 +00:00

48 lines
1.6 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
describe('ZoneAwareError', () => {
// If the environment does not supports stack rewrites, then these tests will fail
// and there is no point in running them.
if (!(Error as any)['stackRewrite']) {
// Jasmine will throw if there are no tests.
it('should pass', () => {});
return;
}
it('should have all properties from NativeError', () => {
let obj: any = new Object();
Error.captureStackTrace(obj);
expect(obj.stack).not.toBeUndefined();
});
it('should support prepareStackTrace', () => {
const originalPrepareStackTrace = (<any>Error).prepareStackTrace;
(<any>Error).prepareStackTrace = function(error: Error, stack: string) {
return stack;
};
let obj: any = new Object();
Error.captureStackTrace(obj);
expect(obj.stack[0].getFileName()).not.toBeUndefined();
(<any>Error).prepareStackTrace = originalPrepareStackTrace;
});
it('should not add additional stacktrace from Zone when use prepareStackTrace', () => {
const originalPrepareStackTrace = (<any>Error).prepareStackTrace;
(<any>Error).prepareStackTrace = function(error: Error, stack: string) {
return stack;
};
let obj: any = new Object();
Error.captureStackTrace(obj);
expect(obj.stack.length).not.toBe(0);
obj.stack.forEach(function(st: any) {
expect(st.getFunctionName()).not.toEqual('zoneCaptureStackTrace');
});
(<any>Error).prepareStackTrace = originalPrepareStackTrace;
});
});