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 #1066

Closed
olegKusov opened this issue Oct 22, 2021 · 3 comments
Closed

waitFor doesn't wait for response with useFakeTimers #1066

olegKusov opened this issue Oct 22, 2021 · 3 comments

Comments

@olegKusov
Copy link

  • @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.

@ms185730
Copy link

ms185730 commented Feb 9, 2022

@olegKusov How was this resolved?

@hovsater
Copy link

hovsater commented Aug 9, 2022

@olegKusov I'm also interested in this. I'm seeing the exact same thing as the original author.

@catz
Copy link

catz commented Oct 24, 2022

Probably linked issue testing-library/react-hooks-testing-library#631

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

4 participants