|
1 | 1 | import { describe, expectTypeOf, it } from 'vitest'
|
2 |
| -import { parseAsString, useQueryState } from '../dist' |
| 2 | +import { |
| 3 | + debounce, |
| 4 | + defaultRateLimit, |
| 5 | + parseAsString, |
| 6 | + throttle, |
| 7 | + useQueryState |
| 8 | +} from '../dist' |
3 | 9 |
|
4 | 10 | describe('types/useQueryState', () => {
|
5 | 11 | it('has a nullable string state by default', () => {
|
@@ -117,4 +123,54 @@ describe('types/useQueryState', () => {
|
117 | 123 | // @ts-expect-error
|
118 | 124 | setBar(() => undefined)
|
119 | 125 | })
|
| 126 | + it('accepts a limitUrlUpdates option', () => { |
| 127 | + useQueryState('foo', { |
| 128 | + limitUrlUpdates: { |
| 129 | + method: 'throttle', |
| 130 | + timeMs: 100 |
| 131 | + } |
| 132 | + }) |
| 133 | + useQueryState('foo', { |
| 134 | + limitUrlUpdates: { |
| 135 | + method: 'debounce', |
| 136 | + timeMs: 100 |
| 137 | + } |
| 138 | + }) |
| 139 | + useQueryState('foo', { limitUrlUpdates: throttle(100) }) |
| 140 | + useQueryState('foo', { limitUrlUpdates: debounce(100) }) |
| 141 | + useQueryState('foo', { limitUrlUpdates: defaultRateLimit }) |
| 142 | + // Using parsers options (builder pattern) |
| 143 | + parseAsString.withOptions({ |
| 144 | + limitUrlUpdates: { |
| 145 | + method: 'throttle', |
| 146 | + timeMs: 100 |
| 147 | + } |
| 148 | + }) |
| 149 | + parseAsString.withOptions({ |
| 150 | + limitUrlUpdates: { |
| 151 | + method: 'debounce', |
| 152 | + timeMs: 100 |
| 153 | + } |
| 154 | + }) |
| 155 | + parseAsString.withOptions({ limitUrlUpdates: throttle(100) }) |
| 156 | + parseAsString.withOptions({ limitUrlUpdates: debounce(100) }) |
| 157 | + parseAsString.withOptions({ limitUrlUpdates: defaultRateLimit }) |
| 158 | + // State updater function |
| 159 | + const [, setState] = useQueryState('foo') |
| 160 | + setState(null, { |
| 161 | + limitUrlUpdates: { |
| 162 | + method: 'throttle', |
| 163 | + timeMs: 100 |
| 164 | + } |
| 165 | + }) |
| 166 | + setState(null, { |
| 167 | + limitUrlUpdates: { |
| 168 | + method: 'debounce', |
| 169 | + timeMs: 100 |
| 170 | + } |
| 171 | + }) |
| 172 | + setState(null, { limitUrlUpdates: throttle(100) }) |
| 173 | + setState(null, { limitUrlUpdates: debounce(100) }) |
| 174 | + setState(null, { limitUrlUpdates: defaultRateLimit }) |
| 175 | + }) |
120 | 176 | })
|
0 commit comments