Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/test/isEqual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import isEqual from '../isEqual';
import warning from '../warning';

describe('isEqual', () => {
let errorSpy: jest.SpyInstance;
let warnSpy: jest.SpyInstance;

beforeAll(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
});

afterEach(() => {
errorSpy.mockReset();
warnSpy.mockReset();
});

afterAll(() => {
errorSpy.mockRestore();
warnSpy.mockRestore();
});

it('should equal', () => {
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('isEqual', () => {
obj.obj = obj;
const obj2 = { a: 1, b: 2, c: [1, 2], obj: null };
warning(false, 'error');
expect(errorSpy).toHaveBeenCalledWith('Warning: error');
expect(warnSpy).toHaveBeenCalledWith('Warning: error');

const valueIsEqual = isEqual(obj, obj2);
expect(valueIsEqual).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion src/warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function warning(valid: boolean, message: string) {
);

if (finalMessage) {
console.error(`Warning: ${finalMessage}`);
console.warn(`Warning: ${finalMessage}`);
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions tests/warning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('warning', () => {
});

it('warning', () => {
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
warning(false, '[antd Component] test hello world');
expect(warnSpy).toHaveBeenCalledWith(
'Warning: [antd Component] test hello world',
Expand Down Expand Up @@ -72,7 +72,6 @@ describe('warning', () => {

describe('preMessage', () => {
it('modify message', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});

warning.preMessage((msg, type) => {
Expand All @@ -87,12 +86,11 @@ describe('warning', () => {
});

warning(false, 'warn');
warning.noteOnce(false, 'note');
expect(warnSpy).toHaveBeenCalledWith('Warning: WW-warn');

expect(errSpy).toHaveBeenCalledWith('Warning: WW-warn');
warning.noteOnce(false, 'note');
expect(warnSpy).toHaveBeenCalledWith('Note: NN-note');

errSpy.mockRestore();
warnSpy.mockRestore();
});
});
Expand Down