diff --git a/src/url/RecoilURLSyncJSONNext.test.tsx b/src/url/RecoilURLSyncJSONNext.test.tsx index 19375b75..67cfa6cb 100644 --- a/src/url/RecoilURLSyncJSONNext.test.tsx +++ b/src/url/RecoilURLSyncJSONNext.test.tsx @@ -77,11 +77,12 @@ describe('', () => { 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') }) @@ -159,11 +160,12 @@ describe('', () => { 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') }) @@ -239,6 +241,10 @@ describe('', () => { 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( @@ -264,11 +270,12 @@ describe('', () => { 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') }) diff --git a/src/url/RecoilURLSyncTransitNext.test.tsx b/src/url/RecoilURLSyncTransitNext.test.tsx index 682ad69c..52f28db4 100644 --- a/src/url/RecoilURLSyncTransitNext.test.tsx +++ b/src/url/RecoilURLSyncTransitNext.test.tsx @@ -82,11 +82,12 @@ describe('', () => { 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') })