@testing-library/react-hooks
Advanced tools
Comparing version 4.0.0-beta.2 to 4.0.0
@@ -11,4 +11,4 @@ "use strict"; | ||
class TimeoutError extends Error { | ||
constructor(utilName, timeout) { | ||
super(`Timed out in ${utilName} after ${timeout}ms.`); | ||
constructor(util, timeout) { | ||
super(`Timed out in ${util.name} after ${timeout}ms.`); | ||
} | ||
@@ -35,3 +35,3 @@ | ||
if (timeout && timeout > 0) { | ||
timeoutId = setTimeout(() => reject(new TimeoutError('waitForNextUpdate', timeout)), timeout); | ||
timeoutId = setTimeout(() => reject(new TimeoutError(waitForNextUpdate, timeout)), timeout); | ||
} | ||
@@ -88,3 +88,3 @@ | ||
if (error instanceof TimeoutError && initialTimeout) { | ||
throw new TimeoutError('waitFor', initialTimeout); | ||
throw new TimeoutError(waitFor, initialTimeout); | ||
} | ||
@@ -104,22 +104,24 @@ | ||
return { | ||
waitFor, | ||
waitForNextUpdate, | ||
waitForValueToChange: async (selector, options = {}) => { | ||
const initialValue = selector(); | ||
const waitForValueToChange = async (selector, options = {}) => { | ||
const initialValue = selector(); | ||
try { | ||
await waitFor(() => selector() !== initialValue, { | ||
suppressErrors: false, | ||
...options | ||
}); | ||
} catch (error) { | ||
if (error instanceof TimeoutError && options.timeout) { | ||
throw new TimeoutError('waitForValueToChange', options.timeout); | ||
} | ||
try { | ||
await waitFor(() => selector() !== initialValue, { | ||
suppressErrors: false, | ||
...options | ||
}); | ||
} catch (error) { | ||
if (error instanceof TimeoutError && options.timeout) { | ||
throw new TimeoutError(waitForValueToChange, options.timeout); | ||
} | ||
throw error; | ||
} | ||
throw error; | ||
} | ||
}; | ||
return { | ||
waitFor, | ||
waitForNextUpdate, | ||
waitForValueToChange | ||
}; | ||
} | ||
@@ -126,0 +128,0 @@ |
{ | ||
"name": "@testing-library/react-hooks", | ||
"version": "4.0.0-beta.2", | ||
"version": "4.0.0", | ||
"description": "Simple and complete React hooks testing utilities that encourage good testing practices.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -10,4 +10,4 @@ import { act } from 'react-test-renderer' | ||
class TimeoutError extends Error { | ||
constructor(utilName: string, timeout: number) { | ||
super(`Timed out in ${utilName} after ${timeout}ms.`) | ||
constructor(util: Function, timeout: number) { | ||
super(`Timed out in ${util.name} after ${timeout}ms.`) | ||
} | ||
@@ -31,3 +31,3 @@ } | ||
timeoutId = setTimeout( | ||
() => reject(new TimeoutError('waitForNextUpdate', timeout)), | ||
() => reject(new TimeoutError(waitForNextUpdate, timeout)), | ||
timeout | ||
@@ -79,3 +79,3 @@ ) | ||
if (error instanceof TimeoutError && initialTimeout) { | ||
throw new TimeoutError('waitFor', initialTimeout) | ||
throw new TimeoutError(waitFor, initialTimeout) | ||
} | ||
@@ -102,3 +102,3 @@ throw error as Error | ||
if (error instanceof TimeoutError && options.timeout) { | ||
throw new TimeoutError('waitForValueToChange', options.timeout) | ||
throw new TimeoutError(waitForValueToChange, options.timeout) | ||
} | ||
@@ -105,0 +105,0 @@ throw error as Error |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
553
1
38642