1
- import { TranslocoService , TranslocoPipe , DefaultParser } from '../../public-api' ;
1
+ import { DefaultParser , TranslocoPipe , TranslocoService } from '../../public-api' ;
2
2
import { Mock } from 'ts-mocks' ;
3
3
import { ChangeDetectorRef } from '@angular/core' ;
4
4
import { load , runLoader } from './transloco.mocks' ;
5
- import { fakeAsync , tick } from '@angular/core/testing' ;
5
+ import { fakeAsync } from '@angular/core/testing' ;
6
6
import { DefaultHandler } from '../transloco-missing-handler' ;
7
- import Spy = jasmine . Spy ;
8
- import { of } from "rxjs" ;
9
- import createSpy = jasmine . createSpy ;
7
+ import { of } from "rxjs" ;
10
8
11
9
describe ( 'TranslocoPipe' , ( ) => {
12
10
let translateServiceMock ;
@@ -17,7 +15,10 @@ describe('TranslocoPipe', () => {
17
15
translateServiceMock = new Mock < TranslocoService > (
18
16
new TranslocoService ( load , new DefaultParser ( ) , new DefaultHandler ( ) , { } )
19
17
) . Object ;
20
- cdrMock = new Mock < ChangeDetectorRef > ( { markForCheck : ( ) => { } } ) . Object ;
18
+ cdrMock = new Mock < ChangeDetectorRef > ( {
19
+ markForCheck : ( ) => {
20
+ }
21
+ } ) . Object ;
21
22
pipe = new TranslocoPipe ( translateServiceMock , { } , cdrMock ) ;
22
23
spyOn ( pipe , 'updateValue' ) . and . callThrough ( ) ;
23
24
} ) ;
@@ -45,13 +46,11 @@ describe('TranslocoPipe', () => {
45
46
46
47
describe ( 'transform' , ( ) => {
47
48
it ( 'should unsubscribe after one emit when not in runtime mode' , fakeAsync ( ( ) => {
48
- pipe = new TranslocoPipe ( translateServiceMock , { runtime : false } , cdrMock ) ;
49
+ pipe = new TranslocoPipe ( translateServiceMock , { runtime : false } , cdrMock ) ;
50
+ const spy = spyOn ( pipe as any , 'takeOne' ) . and . callThrough ( ) ;
49
51
pipe . transform ( 'home' ) ;
50
- const spy = createSpy ( ) . and . callThrough ( ) ;
51
- pipe . subscription . unsubscribe = spy ;
52
52
runLoader ( ) ;
53
- expect ( spy ) . toHaveBeenCalled ( ) ;
54
- expect ( pipe . subscription ) . toBe ( null ) ;
53
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
55
54
} ) ) ;
56
55
57
56
it ( 'should return the key when the key is falsy' , ( ) => {
@@ -75,23 +74,21 @@ describe('TranslocoPipe', () => {
75
74
it ( 'should return the value from the cache' , fakeAsync ( ( ) => {
76
75
pipe . transform ( 'home' ) ;
77
76
runLoader ( ) ;
78
- expect ( pipe . updateValue ) . toHaveBeenCalled ( ) ;
79
- ( pipe . updateValue as Spy ) . calls . reset ( ) ;
77
+ expect ( pipe . updateValue ) . toHaveBeenCalledTimes ( 1 ) ;
80
78
pipe . transform ( 'home' ) ;
81
- expect ( pipe . updateValue ) . not . toHaveBeenCalled ( ) ;
79
+ expect ( pipe . updateValue ) . toHaveBeenCalledTimes ( 1 ) ;
82
80
pipe . transform ( 'a.b.c' ) ;
83
- expect ( pipe . updateValue ) . toHaveBeenCalled ( ) ;
81
+ expect ( pipe . updateValue ) . toHaveBeenCalledTimes ( 2 ) ;
84
82
} ) ) ;
85
83
86
- fit ( 'should return the value from the cache with params' , fakeAsync ( ( ) => {
84
+ it ( 'should return the value from the cache with params' , fakeAsync ( ( ) => {
87
85
pipe . transform ( 'alert' , { value : 'value' } ) ;
88
86
runLoader ( ) ;
89
- expect ( pipe . updateValue ) . toHaveBeenCalled ( ) ;
90
- ( pipe . updateValue as Spy ) . calls . reset ( ) ;
87
+ expect ( pipe . updateValue ) . toHaveBeenCalledTimes ( 1 ) ;
91
88
pipe . transform ( 'alert' , { value : 'value' } ) ;
92
- expect ( pipe . updateValue ) . not . toHaveBeenCalled ( ) ;
89
+ expect ( pipe . updateValue ) . toHaveBeenCalledTimes ( 1 ) ;
93
90
pipe . transform ( 'alert' , { value : 'bla' } ) ;
94
- expect ( pipe . updateValue ) . toHaveBeenCalled ( ) ;
91
+ expect ( pipe . updateValue ) . toHaveBeenCalledTimes ( 2 ) ;
95
92
} ) ) ;
96
93
} ) ;
97
94
0 commit comments