|
| 1 | +import warnIfMissingComponentId from './warnIfMissingComponentId' |
| 2 | + |
| 3 | +describe('warnIfMissingComponentId', () => { |
| 4 | + beforeEach(() => { |
| 5 | + jest.spyOn(console, 'warn').mockReturnValue() |
| 6 | + }) |
| 7 | + |
| 8 | + afterEach(jest.clearAllMocks) |
| 9 | + |
| 10 | + it('should warn if componentId not provided and global is false', () => { |
| 11 | + warnIfMissingComponentId('hook', undefined, false) |
| 12 | + |
| 13 | + expect(console.warn).toBeCalledWith( |
| 14 | + '"hook" hook declared without providing "componentId" context. Make sure you are passing "componentId" as argument or wrapping your screen with "NavigationProvider" or "withNavigation" HOC' |
| 15 | + ) |
| 16 | + }) |
| 17 | + |
| 18 | + it('should warn if componentId not nor global params provided', () => { |
| 19 | + warnIfMissingComponentId('hook') |
| 20 | + |
| 21 | + expect(console.warn).toBeCalledWith( |
| 22 | + '"hook" hook declared without providing "componentId" context. Make sure you are passing "componentId" as argument or wrapping your screen with "NavigationProvider" or "withNavigation" HOC' |
| 23 | + ) |
| 24 | + }) |
| 25 | + |
| 26 | + it('should not warn if global parameter provided provided ', () => { |
| 27 | + warnIfMissingComponentId('hook', undefined, true) |
| 28 | + |
| 29 | + expect(console.warn).not.toBeCalled() |
| 30 | + }) |
| 31 | + |
| 32 | + it('should not warn componentId provided and global is true', () => { |
| 33 | + warnIfMissingComponentId('hook', 'componentId', true) |
| 34 | + |
| 35 | + expect(console.warn).not.toBeCalled() |
| 36 | + }) |
| 37 | + |
| 38 | + it('should not warn componentId provided and global is false', () => { |
| 39 | + warnIfMissingComponentId('hook', 'componentId', false) |
| 40 | + |
| 41 | + expect(console.warn).not.toBeCalled() |
| 42 | + }) |
| 43 | +}) |
0 commit comments