Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should fail on incorrect usage of result', () => {
// $ExpectError
act(() => {}) + 1;
// $ExpectError
act(() => {}).doesNotExist();
// $ExpectError
act(() => {}).then(1);
// $ExpectError
act(() => {}).then(() => {}, 1);
});
it('should remove an alert on close click', () => {
fireEvent.click(getByText(/show alert/i))
const alertElement = getByText(/message/i)
expect(getByText(/message/i)).toBeInTheDocument()
fireEvent.click(getByText(/close/i))
act(jest.runAllTimers)
expect(alertElement).not.toBeInTheDocument()
})
it('should pass on correct usage of result', () => {
act(() => {}).then(() => {});
act(() => {}).then(() => {}, () => {});
});
});
function pushStickyNotification() {
act(() =>
getNotificationsMethods().pushStickyNotification({
id: 'build',
type: 'loading',
title: 'Rebuilding...',
info: 'Your code is updating.'
})
);
}
)
expect(renderedItems).toEqual([0])
rtl.act(forceRender)
expect(renderedItems).toEqual([0, 1])
rtl.act(() => {
store.dispatch({ type: '' })
})
expect(renderedItems).toEqual([0, 1])
rtl.act(forceRender)
expect(renderedItems).toEqual([0, 1, 2])
})
)
const { getByText } = render()
fireEvent.click(getByText(/show alert 0/i))
fireEvent.click(getByText(/show alert 1/i))
const alert0Element = getByText(/message 0/i)
expect(getByText(/message 0/i)).toBeInTheDocument()
const alert1Element = getByText(/message 1/i)
expect(getByText(/message 1/i)).toBeInTheDocument()
fireEvent.click(getByText(/remove all alerts/i))
act(jest.runOnlyPendingTimers)
expect(alert0Element).not.toBeInTheDocument()
expect(alert1Element).not.toBeInTheDocument()
})
export function advanceTimers(ms): void {
now += ms;
Date.now = (): number => now;
act((): void => {
jest.advanceTimersByTime(ms);
});
}
function execute() {
act(() => {
invariant(current, 'Expected throw callback to be set');
current();
});
}
function pushStickyNotifications() {
const { pushStickyNotification } = getNotificationsMethods();
act(() => {
pushStickyNotification({
id: 'one',
type: 'info',
title: 'Check this out',
info: 'Lorem ipsum.'
});
pushStickyNotification({
id: 'two',
type: 'info',
title: 'Take a look at this',
info: 'Lorem ipsum.'
});
});
}
render(depth, () => act(effect))
}