Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waitFor doesn't wait for response with useFakeTimers #983

Closed
olegKusov opened this issue Oct 22, 2021 · 1 comment
Closed

waitFor doesn't wait for response with useFakeTimers #983

olegKusov opened this issue Oct 22, 2021 · 1 comment

Comments

@olegKusov
Copy link

olegKusov commented Oct 22, 2021

  • @testing-library/react version: 12.0.0
  • Testing Framework and version: jest 26.0.24
  • DOM Environment:

Relevant code or config:

beforeEach(() => {
  jest.useFakeTimers();
})

afterEach(() => {
  jest.runOnlyPendingTimers();
  jest.useRealTimers();
});

describe('', () => {
it('should wait for response', async () => {
    renderWithProviders(<Component />, baseState);

    userEvent.click(screen.getByTestId('item-1'));
    userEvent.type(screen.getByTestId('search'), 'Apple juice');
    await waitForElementToBeRemoved(screen.getByTestId('loader'));
});

business logic

const setSearch = createEvent<string | null>();
const $search = restore<string | null>(setSearch, null);
const debouncedSearch = debounce({source: $search, timeout: 1000});

sample({
  clock: debouncedStoreItemSearch
  target: fetchSomeDataFx,
});


const loading = useStore(fetchSomeDataFx.pending);

const Component = () => {
return loading ? <Loader /> : <div>Loaded successfully!</div>
}

What you did:

I have effector as state manager and It has debounce function in patronum helper library. Under the hood it uses setTimeout, that's why I'm using jest fake timers.

What happened:

I saw this issue #661 and @kentcdodds fixed issue with fake timers but my test doesn't wait for response finish. I don't know why. When I log response it show me in console (Cannot log after tests are done. Did you forget to wait for something async in your test?). So it handle response well but doesn't wait for it.

@olegKusov
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant