mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
cc5d3b75e2
* Adjusts tests to no longer rely on CommonJS features. Switches them to ESM * Updates test initialization files to not double-initialize Jasmine now that bootstrap files are loaded after Jasmine. The `jasmine.boot` setup was hacky from `rules_nodejs` and will break in the future regardless if we e.g. use `rules_js` with actual unmodified `jasmine`. PR Close #48521
68 lines
1.8 KiB
TypeScript
68 lines
1.8 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('fake async unpatched clock tests', () => {
|
|
let spy: any;
|
|
|
|
beforeEach(() => {
|
|
spy = jasmine.createSpy('timer');
|
|
jasmine.clock().install();
|
|
});
|
|
|
|
afterEach(() => {
|
|
jasmine.clock().uninstall();
|
|
});
|
|
|
|
it('should check date type correctly', () => {
|
|
const d: any = new Date();
|
|
expect(d instanceof Date).toBe(true);
|
|
});
|
|
|
|
it('should get date diff correctly', () => {
|
|
const start = Date.now();
|
|
jasmine.clock().tick(100);
|
|
const end = Date.now();
|
|
expect(end - start).toBe(100);
|
|
});
|
|
it('should tick correctly', () => {
|
|
const start = Date.now();
|
|
jasmine.clock().tick(100);
|
|
const end = Date.now();
|
|
expect(end - start).toBe(100);
|
|
});
|
|
|
|
it('should mock date correctly', () => {
|
|
const baseTime = new Date(2013, 9, 23);
|
|
jasmine.clock().mockDate(baseTime);
|
|
const start = Date.now();
|
|
expect(start).toBe(baseTime.getTime());
|
|
jasmine.clock().tick(100);
|
|
const end = Date.now();
|
|
expect(end - start).toBe(100);
|
|
expect(end).toBe(baseTime.getTime() + 100);
|
|
});
|
|
|
|
it('should handle new Date correctly', () => {
|
|
const baseTime = new Date(2013, 9, 23);
|
|
jasmine.clock().mockDate(baseTime);
|
|
const start = new Date();
|
|
expect(start.getTime()).toBe(baseTime.getTime());
|
|
jasmine.clock().tick(100);
|
|
const end = new Date();
|
|
expect(end.getTime() - start.getTime()).toBe(100);
|
|
expect(end.getTime()).toBe(baseTime.getTime() + 100);
|
|
});
|
|
|
|
it('should handle setTimeout correctly', () => {
|
|
setTimeout(spy, 100);
|
|
expect(spy).not.toHaveBeenCalled();
|
|
jasmine.clock().tick(100);
|
|
expect(spy).toHaveBeenCalled();
|
|
});
|
|
})
|