|
| 1 | +import {DiffObjPipe} from './diff-obj'; |
| 2 | + |
| 3 | +describe('DiffObj Pipe', () => { |
| 4 | + let pipe: DiffObjPipe; |
| 5 | + |
| 6 | + beforeEach(() => { |
| 7 | + pipe = new DiffObjPipe(); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should keep the element the same way if its not an object', () => { |
| 11 | + expect(pipe.transform([1, 2, 3], {})).toEqual({}); |
| 12 | + expect(pipe.transform([], {})).toEqual({}); |
| 13 | + expect(pipe.transform('foo', {})).toEqual({}); |
| 14 | + expect(pipe.transform(null, {})).toEqual({}); |
| 15 | + expect(pipe.transform(undefined, {})).toEqual({}); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should return an empty object when there is no difference', () => { |
| 19 | + expect(pipe.transform({}, {})).toEqual({}); |
| 20 | + expect(pipe.transform({a: 1}, {a: 1})).toEqual({}); |
| 21 | + expect(pipe.transform({a: {b: 1}, c: 3}, {a: {b: 1}, c: 3})).toEqual({}); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should return a diff object', () => { |
| 25 | + expect(pipe.transform({a: 1}, {a: 2})).toEqual({a: 1}); |
| 26 | + expect(pipe.transform({a: 1, b: 1}, {a: 1, b: 2})).toEqual({b: 1}); |
| 27 | + expect(pipe.transform({a: 1, b: true}, {a: 1, b: 2})).toEqual({b: true}); |
| 28 | + expect(pipe.transform({a: 1, b: {c: 1}}, {a: 1, b: {c: 2}})).toEqual({b: {c: 1}}); |
| 29 | + }); |
| 30 | +}); |
0 commit comments