Files
headlessui/jest/custom-matchers.ts
T
Robin Malfait ef00732685 cleanup and consistency (#213)
- Made the use of `const` and `let` consistent
- import required functions and types from 'react' instead of using the
  `React.` namespace.
- Added `Expand` type, which can expand complex types to their "final"
  result.
- Ensured that we use `as const` for DEFAULT_XXX_TAG where we used a
  string. So that we have the type of `div` instead of `string` for
  example.
- Used `interface` over `type` where possible. I'm personally more of a
  `type` fan. But the TypeScript recommends `interfaces` where possible
  because they are faster, yield better error messages and so on.
2021-01-30 14:46:54 +01:00

32 lines
839 B
TypeScript

import '@testing-library/jest-dom/extend-expect'
// Assuming requestAnimationFrame is roughly 60 frames per second
let frame = 1000 / 60
let amountOfFrames = 2
let formatter = new Intl.NumberFormat('en')
expect.extend({
toBeWithinRenderFrame(actual, expected) {
let min = expected - frame * amountOfFrames
let max = expected + frame * amountOfFrames
let pass = actual >= min && actual <= max
return {
message: pass
? () => {
return `expected ${actual} not to be within range of a frame ${formatter.format(
min
)} - ${formatter.format(max)}`
}
: () => {
return `expected ${actual} not to be within range of a frame ${formatter.format(
min
)} - ${formatter.format(max)}`
},
pass,
}
},
})