Skip to content

Commit d446489

Browse files
authored
mix missing act() and silence noisy test (#146)
1 parent 8491e86 commit d446489

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/__tests__/unit/ui/link/test.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22

33
import { mount } from 'enzyme';
44
import { defaultRegistry } from 'react-sweet-state';
5+
import { act } from 'react-dom/test-utils';
56

67
import { LinkProps } from '../../../../common/types';
78
import { Router } from '../../../../controllers/router';
@@ -36,6 +37,15 @@ const baseClickEvent = {
3637
const newPath = '/my-new-path';
3738
const eventModifiers = [['metaKey'], ['altKey'], ['ctrlKey'], ['shiftKey']];
3839

40+
// https://github.com/facebook/jest/pull/5267#issuecomment-356605468
41+
const withoutConsoleError = (fn: () => void) => () => {
42+
const consoleError = jest
43+
.spyOn<Console, 'error'>(console, 'error')
44+
.mockImplementation(() => undefined);
45+
fn();
46+
consoleError.mockRestore();
47+
};
48+
3949
describe('<Link />', () => {
4050
const mountInRouter = (
4151
children: LinkProps['children'],
@@ -240,7 +250,7 @@ describe('<Link />', () => {
240250
params: { id: '1' },
241251
query: { foo: 'bar' },
242252
});
243-
await Promise.resolve();
253+
await act(() => Promise.resolve());
244254
const component = wrapper.find('Link');
245255

246256
component.simulate('click', baseClickEvent);
@@ -257,7 +267,11 @@ describe('<Link />', () => {
257267
});
258268

259269
it('should error if required route parameters are missing', () => {
260-
expect(() => mountInRouter('my link', { to: route })).toThrow();
270+
expect(
271+
withoutConsoleError(() => {
272+
mountInRouter('my link', { to: route });
273+
})
274+
).toThrow();
261275
});
262276
});
263277

0 commit comments

Comments
 (0)