forked from danrevah/ngx-pipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrap.spec.ts
37 lines (31 loc) · 1.73 KB
/
wrap.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 { WrapPipe } from './wrap';
describe('WrapPipe Tests', () => {
let pipe: WrapPipe;
beforeEach(() => {
pipe = new WrapPipe();
});
it('Should not do anything if main text is not a string', () => {
expect(pipe.transform(null)).toEqual(null);
expect(pipe.transform(undefined)).toEqual(undefined);
expect(pipe.transform(42 as any)).toEqual(42 as any);
expect(pipe.transform({name: 'foo'} as any)).toEqual({name: 'foo'} as any);
});
it('Should skip the prefix if prefix text is not a string', () => {
expect(pipe.transform('main text', undefined)).toEqual('main text');
expect(pipe.transform('main text', undefined)).toEqual('main text');
expect(pipe.transform('main text', 42 as any)).toEqual('main text');
expect(pipe.transform('main text', {name: 'foo'} as any)).toEqual('main text');
});
it('Should skip the suffix if suffix text is not a string', () => {
expect(pipe.transform('main text', 'great prefix ', undefined)).toEqual('great prefix main text');
expect(pipe.transform('main text', 'great prefix ', undefined)).toEqual('great prefix main text');
expect(pipe.transform('main text', 'great prefix ', 42 as any)).toEqual('great prefix main text');
expect(pipe.transform('main text', 'great prefix ', {name: 'foo'} as any)).toEqual('great prefix main text');
});
it('Should wrap properly', () => {
expect(pipe.transform('main text')).toEqual('main text');
expect(pipe.transform('main text', 'great prefix ', ' awesome suffix')).toEqual('great prefix main text awesome suffix');
expect(pipe.transform('main text', 'only prefix ')).toEqual('only prefix main text');
expect(pipe.transform('main text', undefined, ' only suffix')).toEqual('main text only suffix');
});
});