File size: 1,119 Bytes
1e92f2d | 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 38 39 40 41 42 43 44 45 46 47 | /* eslint-disable no-console */
import { warn } from '../warn';
describe('warn', () => {
if (__DEV__) {
test('logs when the condition is unmet', () => {
expect(() => {
warn(false, 'warning');
}).toWarnDev('[InstantSearch] warning');
});
test('does not log when the condition is met', () => {
expect(() => {
warn(true, 'warning');
}).not.toWarnDev();
});
test('trims the message', () => {
expect(() => {
warn(false, '\nwarning! ');
}).toWarnDev('[InstantSearch] warning!');
});
test('warns a message a single time', () => {
const originalConsoleWarn = console.warn;
console.warn = jest.fn();
warn(false, 'warning1');
warn(false, 'warning1');
warn(false, 'warning2');
expect(console.warn).toHaveBeenCalledTimes(2);
expect(console.warn).toHaveBeenNthCalledWith(
1,
'[InstantSearch] warning1'
);
expect(console.warn).toHaveBeenNthCalledWith(
2,
'[InstantSearch] warning2'
);
console.warn = originalConsoleWarn;
});
}
});
|