ef00732685
- 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.
32 lines
839 B
TypeScript
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,
|
|
}
|
|
},
|
|
})
|