Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/nuqs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"@types/react-dom": "catalog:react19",
"@vitejs/plugin-react": "^4.3.4",
"@vitest/coverage-v8": "^3.0.9",
"fast-check": "^4.0.1",
"jsdom": "^26.0.0",
"next": "15.2.4",
"react": "catalog:react19",
Expand Down
19 changes: 19 additions & 0 deletions packages/nuqs/src/url-encoding.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fc from 'fast-check'
import { describe, expect, test, vi } from 'vitest'
import { encodeQueryValue, renderQueryString } from './url-encoding'

Expand Down Expand Up @@ -47,6 +48,24 @@ describe('url-encoding/encodeQueryValue', () => {
expect(e('kool&thegang')).toBe('kool%26thegang')
expect(e('a&b=c')).toBe('a%26b=c')
})

test.each([
{ label: 'ASCII', unit: 'binary-ascii' },
{ label: 'Printable characters', unit: 'grapheme' },
{ label: 'Full Unicode range', unit: 'binary' },
{
label: 'Special ASCII characters',
unit: fc.constantFrom(...'-._~!$()*,;=:@/?[]{}\\|^')
}
] as const)('Property-based fuzzy testing - $label', ({ unit }) => {
fc.assert(
fc.property(fc.string({ unit }), str => {
const search = `?key=${encodeQueryValue(str)}`
const expected = new URLSearchParams(search).get('key')
expect(expected).toBe(str)
})
)
})
})

describe('url-encoding/renderQueryString', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/nuqs/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import * as matchers from '@testing-library/jest-dom/matchers'
import { cleanup } from '@testing-library/react'
import fc, { VerbosityLevel } from 'fast-check'
import { afterEach, expect } from 'vitest'

expect.extend(matchers)

// https://testing-library.com/docs/react-testing-library/api/#cleanup
afterEach(cleanup)

fc.configureGlobal({
numRuns: 1000,
verbose: process.env.CI ? VerbosityLevel.None : VerbosityLevel.VeryVerbose,
interruptAfterTimeLimit: 5000
})
50 changes: 47 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading