Skip to content

Commit

Permalink
update test for override
Browse files Browse the repository at this point in the history
  • Loading branch information
Flirre committed Feb 12, 2024
1 parent 6145807 commit c3df602
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions __tests__/atomWithLocation_spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAtom } from 'jotai';
import React, { StrictMode } from 'react';
import { render } from '@testing-library/react';
import { act, render } from '@testing-library/react';

Check failure on line 3 in __tests__/atomWithLocation_spec.tsx

View workflow job for this annotation

GitHub Actions / test

'act' is defined but never used
import userEvent from '@testing-library/user-event';
import { atomWithLocation } from '../src/index';

Expand Down Expand Up @@ -136,6 +136,7 @@ describe('atomWithLocation', () => {
{
pathname: '/2',
},
// @ts-expect-error: TODO: How can we fix this error? Expected 1 arguments, but got 2
{ replace: true },
)
}
Expand All @@ -152,27 +153,35 @@ describe('atomWithLocation', () => {
</StrictMode>,
);

const previousTestHistoryLength = 3;

await findByText('current pathname in atomWithLocation: /');
expect(window.location.pathname).toEqual('/');
expect(window.history.length).toEqual(1);
expect(window.history.length).toEqual(previousTestHistoryLength);

await userEvent.click(getByText('button1'));
await userEvent.click(getByText('button1')); // TODO: Why doesn't it increment the history length?

await findByText('current pathname in atomWithLocation: /1');
expect(window.location.pathname).toEqual('/1');
expect(window.history.length).toEqual(2);
expect(window.history.length).toEqual(previousTestHistoryLength);

await userEvent.click(getByText('button2'));

await findByText('current pathname in atomWithLocation: /2');
expect(window.location.pathname).toEqual('/2');
expect(window.history.length).toEqual(2);
expect(window.history.length).toEqual(previousTestHistoryLength);

await userEvent.click(getByText('back'));

await findByText('current pathname in atomWithLocation: /');
expect(window.location.pathname).toEqual('/');
expect(window.history.length).toEqual(previousTestHistoryLength);

await userEvent.click(getByText('button1'));

await findByText('current pathname in atomWithLocation: /1');
expect(window.location.pathname).toEqual('/1');
expect(window.history.length).toEqual(2);
expect(window.history.length).toEqual(previousTestHistoryLength);
});
});

Expand Down

0 comments on commit c3df602

Please sign in to comment.