-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathTimeAgoPipe.spec.ts
37 lines (33 loc) · 1.38 KB
/
TimeAgoPipe.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import 'es6-shim';
import 'reflect-metadata';
import * as moment from 'moment';
import {TimeAgoPipe} from './TimeAgoPipe';
describe('TimeAgoPipe', () => {
describe('#transform', () => {
afterEach(function() {
jasmine.clock().uninstall();
});
it('should transform the current date to "a few seconds ago"', () => {
const pipe = new TimeAgoPipe(null);
expect(pipe.transform(new Date())).toBe('a few seconds ago');
});
it('should automatically update the text as time passes', () => {
const changeDetectorMock = jasmine.createSpyObj('ChangeDetectorRef', ['markForCheck']);
const pipe = new TimeAgoPipe(changeDetectorMock);
jasmine.clock().install();
expect(pipe.transform(new Date())).toBe('a few seconds ago');
expect(changeDetectorMock.markForCheck).not.toHaveBeenCalled();
jasmine.clock().tick(60000);
expect(changeDetectorMock.markForCheck).toHaveBeenCalled();
});
it('should remove all timer when destroyed', () => {
const changeDetectorMock = jasmine.createSpyObj('ChangeDetectorRef', ['markForCheck']);
const pipe = new TimeAgoPipe(changeDetectorMock);
jasmine.clock().install();
expect(pipe.transform(new Date())).toBe('a few seconds ago');
pipe.ngOnDestroy();
jasmine.clock().tick(60000);
expect(changeDetectorMock.markForCheck).not.toHaveBeenCalled();
});
});
});