Skip to content

Commit

Permalink
test: simulate Static/SSG rendering properely
Browse files Browse the repository at this point in the history
  • Loading branch information
koichik committed Jul 16, 2022
1 parent 9a2a8ac commit bd8c1a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/url/RecoilURLSyncJSONNext.test.tsx
Expand Up @@ -77,11 +77,12 @@ describe('<RecoilURLSyncJSONNext />', () => {
await waitFor(() =>
expect(getByTestId('foo').textContent).toBe('FooFoo')
)
urlPath = mockRouter.asPath
})

describe('then, navigate (pushstate)', () => {
beforeEach(() => {
urlPath = mockRouter.asPath // save current URL before push()

act(() => {
mockRouter.push('/next')
})
Expand Down Expand Up @@ -159,11 +160,12 @@ describe('<RecoilURLSyncJSONNext />', () => {
await waitFor(() =>
expect(getByTestId('foo').textContent).toBe('BarFoo')
)
urlPath = mockRouter.asPath
})

describe('then, navigate (pushstate)', () => {
beforeEach(() => {
urlPath = mockRouter.asPath // save current URL before push()

act(() => {
mockRouter.push('/next')
})
Expand Down Expand Up @@ -239,6 +241,10 @@ describe('<RecoilURLSyncJSONNext />', () => {
beforeEach(() => {
act(() => {
mockRouter.isReady = true
// because mockRouter holds router's snapshot into useState(),
// we need to fire 'routeChangeComplete' event to update the snapshot.
// otherwise isReady will not be reflected.
mockRouter.events.emit('routeChangeComplete')
rerender(
<App>
<Child />
Expand All @@ -264,11 +270,12 @@ describe('<RecoilURLSyncJSONNext />', () => {
await waitFor(() =>
expect(getByTestId('foo').textContent).toBe('BarFoo')
)
urlPath = mockRouter.asPath
})

describe('then, navigate (pushstate)', () => {
beforeEach(() => {
urlPath = mockRouter.asPath // save current URL before push()

act(() => {
mockRouter.push('/next')
})
Expand Down
3 changes: 2 additions & 1 deletion src/url/RecoilURLSyncTransitNext.test.tsx
Expand Up @@ -82,11 +82,12 @@ describe('<RecoilURLSyncTransitNext />', () => {
await waitFor(() =>
expect(getByTestId('foo').textContent).toBe('FooFoo')
)
urlPath = mockRouter.asPath
})

describe('then, navigate (pushstate)', () => {
beforeEach(() => {
urlPath = mockRouter.asPath // save current URL before push()

act(() => {
mockRouter.push('/next')
})
Expand Down

0 comments on commit bd8c1a8

Please sign in to comment.