|
1 | 1 | import { configure, getConfig, resetToDefaults } from '../config'; |
| 2 | +import { _console } from '../helpers/logger'; |
2 | 3 |
|
3 | 4 | beforeEach(() => { |
4 | 5 | resetToDefaults(); |
| 6 | + jest.spyOn(_console, 'warn').mockImplementation(() => {}); |
| 7 | +}); |
| 8 | + |
| 9 | +afterEach(() => { |
| 10 | + jest.restoreAllMocks(); |
5 | 11 | }); |
6 | 12 |
|
7 | 13 | test('getConfig() returns existing configuration', () => { |
@@ -46,3 +52,45 @@ test('configure handles alias option defaultHidden', () => { |
46 | 52 | configure({ defaultHidden: true }); |
47 | 53 | expect(getConfig().defaultIncludeHiddenElements).toEqual(true); |
48 | 54 | }); |
| 55 | + |
| 56 | +test('does not warn when no options are passed', () => { |
| 57 | + configure({}); |
| 58 | + |
| 59 | + expect(_console.warn).not.toHaveBeenCalled(); |
| 60 | +}); |
| 61 | + |
| 62 | +test('does not warn when only valid options are passed', () => { |
| 63 | + configure({ |
| 64 | + asyncUtilTimeout: 2000, |
| 65 | + defaultIncludeHiddenElements: true, |
| 66 | + defaultDebugOptions: { message: 'test' }, |
| 67 | + defaultHidden: false, |
| 68 | + }); |
| 69 | + |
| 70 | + expect(_console.warn).not.toHaveBeenCalled(); |
| 71 | +}); |
| 72 | + |
| 73 | +test('warns when unknown option is passed', () => { |
| 74 | + configure({ unknownOption: 'value' } as any); |
| 75 | + |
| 76 | + expect(_console.warn).toHaveBeenCalledTimes(1); |
| 77 | + const warningMessage = jest.mocked(_console.warn).mock.calls[0][0]; |
| 78 | + expect(warningMessage).toContain('Unknown option(s) passed to configure: unknownOption'); |
| 79 | + expect(warningMessage).toContain('config.test.ts'); |
| 80 | +}); |
| 81 | + |
| 82 | +test('warns when multiple unknown options are passed', () => { |
| 83 | + configure({ asyncUtilTimeout: 1000, unknown1: 'value1', unknown2: 'value2' } as any); |
| 84 | + |
| 85 | + expect(_console.warn).toHaveBeenCalledTimes(1); |
| 86 | + const warningMessage = jest.mocked(_console.warn).mock.calls[0][0]; |
| 87 | + expect(warningMessage).toContain('Unknown option(s) passed to configure: unknown1, unknown2'); |
| 88 | + expect(warningMessage).toContain('config.test.ts'); |
| 89 | +}); |
| 90 | + |
| 91 | +test('still configures correctly when unknown options are passed', () => { |
| 92 | + configure({ asyncUtilTimeout: 3000, unknownOption: 'value' } as any); |
| 93 | + |
| 94 | + expect(_console.warn).toHaveBeenCalledTimes(1); |
| 95 | + expect(getConfig().asyncUtilTimeout).toBe(3000); |
| 96 | +}); |
0 commit comments