describe('MapPipe', () => { let pipe: SomePipe; const fn = function (item) { return item === 2; }; beforeEach(() => { pipe = new SomePipe(); }); it('Should return true', () => { const array = [0, 1, 2, 3]; expect(pipe.transform(array, fn)).toEqual(true); expect(array).toEqual([0, 1, 2, 3]); // Check integrity }); it('Should return false', () => { expect(pipe.transform([1,3], fn)).toEqual(false); }); it('Should return the value unchanged', () => { expect(pipe.transform('a', null)).toEqual('a'); }); })
describe('TailPipe', () => { let pipe: TailPipe; beforeEach(() => { pipe = new TailPipe(); }); it('Should return []', () => { expect(pipe.transform([])).toEqual([]); }); it('Should return [2]', () => { expect(pipe.transform([1, 2])).toEqual([2]); }); it ('Should return [2, 3]', () => { expect(pipe.transform([1, 2, 3])).toEqual([2, 3]); }); it('Should return the value unchanged', () => { expect(pipe.transform('a')).toEqual('a'); }); });
describe('CapitalizePipe', () => { let pipe: CapitalizePipe; beforeEach(() => { pipe = new CapitalizePipe(); }); it('Should returned the capitalized string', () => { expect(pipe.transform('abcd', false)).toEqual('Abcd'); }); it('Should returned the capitalized string #2', () => { expect(pipe.transform('abcd aa', false)).toEqual('Abcd aa'); }); it('Should returned the capitalized string #3', () => { expect(pipe.transform('abCD aA', false)).toEqual('Abcd aa'); }); it('Should returned the capitalized string #4', () => { expect(pipe.transform('abCD aA', true)).toEqual('Abcd Aa'); }); it('Should return the value unchanged', () => { expect(pipe.transform(1, null)).toEqual(1); }); });
describe('FloorPipe', () => { let pipe: FloorPipe; beforeEach(() => { pipe = new FloorPipe(); }); it('Should return 3', () => { expect(pipe.transform(3.4, 0)).toEqual(3); }); it('Should return 1', () => { expect(pipe.transform(1, 0)).toEqual(1); }); it('Should return 0', () => { expect(pipe.transform(0.65, 0)).toEqual(0); }); it('Should return 1.5', () => { expect(pipe.transform(1.5, 1)).toEqual(1.5); }); it('Should return 1.54', () => { expect(pipe.transform(1.5444, 2)).toEqual(1.54); }); });
describe('TestPipe', () => { let pipe: TestPipe; beforeEach(() => { pipe = new TestPipe(); }); it('Should return true', () => { const result = pipe.transform('abc', /a/g); expect(result).toEqual(true); }); it('Should return false', () => { const result = pipe.transform('abc', /d/g); expect(result).toEqual(false); }); // Just use test function ... it('Should return the value unchanged', () => { expect(pipe.transform(1, null, null)).toEqual(1); }); });
describe('IsObjectPipe', () => { let pipe: IsObjectPipe; beforeEach(() => { pipe = new IsObjectPipe(); }); it('Should return true', () => { expect(pipe.transform({})).toEqual(true); }); it('Should return false', () => { expect(pipe.transform(1)).toEqual(false); }); it('Should return true #2', () => { expect(pipe.transform([])).toEqual(true); }); it('Should return false #3', () => { expect(pipe.transform('a')).toEqual(false); }); });
describe('JoinPipe ', () => { let pipe: JoinPipe; beforeEach(() => { pipe = new JoinPipe (); }); it('Should return "abcd"', () => { expect(pipe.transform(['a', 'b', 'c', 'd'], '')).toEqual('abcd'); }); it('Should return abc123', () => { expect(pipe.transform(['a', 'b', 'c', 1, 2, 3], '')).toEqual('abc123'); }); it ('Should return 1a2a3', () => { expect(pipe.transform([1, 2, 3], 'a')).toEqual('1a2a3'); }); it('Should return the value unchanged', () => { expect(pipe.transform('a', '')).toEqual('a'); }); });
describe('RangePipe', () => { let pipe: RangePipe; beforeEach(() => { pipe = new RangePipe(); }); it('Should return a range from 1 to 10', () => { expect(pipe.transform([], 10, 1)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); }); it('Should return a range from 0 to 4', () => { expect(pipe.transform([], 5, 0)).toEqual([0, 1, 2, 3, 4]); }); it('Should return a range from -2 to +2', () => { expect(pipe.transform([], 5, -2)).toEqual([-2, -1, 0, 1, 2]); }); it ('Should return a range from 0 to 18 with a step of 2', () => { expect(pipe.transform([], 10, 0, 2)).toEqual([0, 2, 4, 6, 8, 10, 12, 14, 16, 18]); }); })
describe('TakePipe', () => { let pipe: TakePipe; beforeEach(() => { pipe = new TakePipe(); }); it('Should return []', () => { expect(pipe.transform([])).toEqual([]); }); it('Should return [1]', () => { const value = [1, 2, 3, 4]; expect(pipe.transform(value)).toEqual([1]); expect(value).toEqual([1, 2, 3, 4]); // Check integrity }); it ('Should return [1, 2]', () => { expect(pipe.transform([1, 2, 3, 4], 2)).toEqual([1, 2]); }); it('Should return the value unchanged', () => { expect(pipe.transform('a')).toEqual('a'); }); })
describe('CountPipe', () => { let pipe: CountPipe; beforeEach(() => { pipe = new CountPipe(); }); it('Should return the length of the collection', () => { expect(pipe.transform([1,2])).toEqual(2); }); it('Should return the length of the object (keys)', () => { expect(pipe.transform({ a: 1, b: 2, c: 3})).toEqual(3); }); it('Should return the value unchanged', () => { expect(pipe.transform('a')).toEqual('a'); }); });