isCodecBijective @vuqs/core/testing
The full bijectivity check for a custom codec: both round-trip directions hold, and the serialized/parsed forms match the expected values.
Usage
ts
import { codecs } from '@vuqs/core'
import { isCodecBijective } from '@vuqs/core/testing'
import { expect } from 'vitest'
expect(isCodecBijective(codecs.integer, '42', 42)).toBe(true)
expect(() => isCodecBijective(codecs.integer, '42', 47)).toThrow()Type
ts
function isCodecBijective<T>(codec: Codec<T>, serialized: ParsedQueryValue, input: T): booleanParameters
codec: Codec<T>- The codec under test.
serialized: ParsedQueryValue- The codec's canonical serialized form of
input.
- The codec's canonical serialized form of
input: T- The value
serializedshould parse back to, compared bycodec.eq.
- The value
Return value
valid: booleantruewhenserialize(input)equalsserialized,parse(serialized)equalsinput, and both directions round-trip. Otherwise throws, naming the side that broke.