Files
headlessui/jest/custom-matchers.ts
T
Robin Malfait 672afbe9f8 setup monorepo
2020-09-16 18:19:33 +02:00

32 lines
770 B
TypeScript

// Assuming requestAnimationFrame is roughly 60 frames per second
const frame = 1000 / 60
const formatter = new Intl.NumberFormat('en')
expect.extend({
toBeWithinRenderFrame(actual, expected) {
const min = expected - frame
const max = expected + frame
const pass = actual >= min && actual <= max
if (pass) {
return {
message: () =>
`expected ${actual} not to be within range of a frame ${formatter.format(
min
)} - ${formatter.format(max)}`,
pass: true,
}
} else {
return {
message: () =>
`expected ${actual} to be within range of a frame ${formatter.format(
min
)} - ${formatter.format(max)}`,
pass: false,
}
}
},
})