Skip to content

Commit f8510f5

Browse files
committed
test: Use HOC in tests
1 parent 8a4b166 commit f8510f5

File tree

4 files changed

+34
-52
lines changed

4 files changed

+34
-52
lines changed

packages/e2e/react-router/src/components/counter-button.test.tsx

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
import { render, screen } from '@testing-library/react'
22
import userEvent from '@testing-library/user-event'
3-
import { NuqsTestingAdapter, type UrlUpdateEvent } from 'nuqs/adapters/testing'
3+
import {
4+
withNuqsTestingAdapter,
5+
type UrlUpdateEvent
6+
} from 'nuqs/adapters/testing'
47
import { describe, expect, it, vi } from 'vitest'
58
import { CounterButton } from './counter-button'
69

710
describe('CounterButton', () => {
811
it('should render the button with state loaded from the URL', () => {
912
render(<CounterButton />, {
10-
wrapper: ({ children }) => (
11-
<NuqsTestingAdapter searchParams="?count=42">
12-
{children}
13-
</NuqsTestingAdapter>
14-
)
13+
wrapper: withNuqsTestingAdapter({ searchParams: '?count=42' })
1514
})
1615
expect(screen.getByRole('button')).toHaveTextContent('count is 42')
1716
})
1817
it('should increment the count when clicked', async () => {
1918
const user = userEvent.setup()
2019
const onUrlUpdate = vi.fn<[UrlUpdateEvent]>()
2120
render(<CounterButton />, {
22-
wrapper: ({ children }) => (
23-
<NuqsTestingAdapter searchParams="?count=42" onUrlUpdate={onUrlUpdate}>
24-
{children}
25-
</NuqsTestingAdapter>
26-
)
21+
wrapper: withNuqsTestingAdapter({
22+
searchParams: '?count=42',
23+
onUrlUpdate
24+
})
2725
})
2826
const button = screen.getByRole('button')
2927
await user.click(button)

packages/e2e/react-router/src/components/search-input.test.tsx

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import { render, screen } from '@testing-library/react'
22
import userEvent from '@testing-library/user-event'
3-
import { NuqsTestingAdapter, type UrlUpdateEvent } from 'nuqs/adapters/testing'
3+
import {
4+
withNuqsTestingAdapter,
5+
type UrlUpdateEvent
6+
} from 'nuqs/adapters/testing'
47
import { describe, expect, it, vi } from 'vitest'
58
import { SearchInput } from './search-input'
69

710
describe('SearchInput', () => {
811
it('should render the input with state loaded from the URL', () => {
912
render(<SearchInput />, {
10-
wrapper: ({ children }) => (
11-
<NuqsTestingAdapter
12-
searchParams={{
13-
search: 'nuqs'
14-
}}
15-
>
16-
{children}
17-
</NuqsTestingAdapter>
18-
)
13+
wrapper: withNuqsTestingAdapter({ searchParams: { search: 'nuqs' } })
1914
})
2015
const input = screen.getByRole('search')
2116
expect(input).toHaveValue('nuqs')
@@ -24,11 +19,9 @@ describe('SearchInput', () => {
2419
const user = userEvent.setup()
2520
const onUrlUpdate = vi.fn<[UrlUpdateEvent]>()
2621
render(<SearchInput />, {
27-
wrapper: ({ children }) => (
28-
<NuqsTestingAdapter onUrlUpdate={onUrlUpdate} rateLimitFactor={0}>
29-
{children}
30-
</NuqsTestingAdapter>
31-
)
22+
wrapper: withNuqsTestingAdapter({
23+
onUrlUpdate
24+
})
3225
})
3326
const expectedState = 'Hello, world!'
3427
const expectedParam = 'Hello,+world!'

packages/e2e/react/src/components/counter-button.test.tsx

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
import { render, screen } from '@testing-library/react'
22
import userEvent from '@testing-library/user-event'
3-
import { NuqsTestingAdapter, type UrlUpdateEvent } from 'nuqs/adapters/testing'
3+
import {
4+
withNuqsTestingAdapter,
5+
type UrlUpdateEvent
6+
} from 'nuqs/adapters/testing'
47
import { describe, expect, it, vi } from 'vitest'
58
import { CounterButton } from './counter-button'
69

710
describe('CounterButton', () => {
811
it('should render the button with state loaded from the URL', () => {
912
render(<CounterButton />, {
10-
wrapper: ({ children }) => (
11-
<NuqsTestingAdapter searchParams="?count=42">
12-
{children}
13-
</NuqsTestingAdapter>
14-
)
13+
wrapper: withNuqsTestingAdapter({ searchParams: '?count=42' })
1514
})
1615
expect(screen.getByRole('button')).toHaveTextContent('count is 42')
1716
})
1817
it('should increment the count when clicked', async () => {
1918
const user = userEvent.setup()
2019
const onUrlUpdate = vi.fn<[UrlUpdateEvent]>()
2120
render(<CounterButton />, {
22-
wrapper: ({ children }) => (
23-
<NuqsTestingAdapter searchParams="?count=42" onUrlUpdate={onUrlUpdate}>
24-
{children}
25-
</NuqsTestingAdapter>
26-
)
21+
wrapper: withNuqsTestingAdapter({
22+
searchParams: '?count=42',
23+
onUrlUpdate
24+
})
2725
})
2826
const button = screen.getByRole('button')
2927
await user.click(button)

packages/e2e/react/src/components/search-input.test.tsx

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import { render, screen } from '@testing-library/react'
22
import userEvent from '@testing-library/user-event'
3-
import { NuqsTestingAdapter, type UrlUpdateEvent } from 'nuqs/adapters/testing'
3+
import {
4+
withNuqsTestingAdapter,
5+
type UrlUpdateEvent
6+
} from 'nuqs/adapters/testing'
47
import { describe, expect, it, vi } from 'vitest'
58
import { SearchInput } from './search-input'
69

710
describe('SearchInput', () => {
811
it('should render the input with state loaded from the URL', () => {
912
render(<SearchInput />, {
10-
wrapper: ({ children }) => (
11-
<NuqsTestingAdapter
12-
searchParams={{
13-
search: 'nuqs'
14-
}}
15-
>
16-
{children}
17-
</NuqsTestingAdapter>
18-
)
13+
wrapper: withNuqsTestingAdapter({ searchParams: { search: 'nuqs' } })
1914
})
2015
const input = screen.getByRole('search')
2116
expect(input).toHaveValue('nuqs')
@@ -24,11 +19,9 @@ describe('SearchInput', () => {
2419
const user = userEvent.setup()
2520
const onUrlUpdate = vi.fn<[UrlUpdateEvent]>()
2621
render(<SearchInput />, {
27-
wrapper: ({ children }) => (
28-
<NuqsTestingAdapter onUrlUpdate={onUrlUpdate} rateLimitFactor={0}>
29-
{children}
30-
</NuqsTestingAdapter>
31-
)
22+
wrapper: withNuqsTestingAdapter({
23+
onUrlUpdate
24+
})
3225
})
3326
const expectedState = 'Hello, world!'
3427
const expectedParam = 'Hello,+world!'

0 commit comments

Comments
 (0)