Socket
Socket
Sign inDemoInstall

@testing-library/react-hooks

Package Overview
Dependencies
Maintainers
16
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testing-library/react-hooks - npm Package Compare versions

Comparing version 3.7.0 to 4.0.0-beta.1

lib/asyncUtils.d.ts

70

lib/asyncUtils.js

@@ -10,8 +10,9 @@ "use strict";

function createTimeoutError(utilName, {
timeout
}) {
const timeoutError = new Error(`Timed out in ${utilName} after ${timeout}ms.`);
timeoutError.timeout = true;
return timeoutError;
class TimeoutError extends Error {
constructor(utilName, {
timeout
}) {
super(`Timed out in ${utilName} after ${timeout}ms.`);
}
}

@@ -25,4 +26,2 @@

let hasWarnedDeprecatedWait = false;
function asyncUtils(addResolver) {

@@ -36,4 +35,4 @@ let nextUpdatePromise = null;

if (options.timeout > 0) {
timeoutId = setTimeout(() => reject(createTimeoutError('waitForNextUpdate', options)), options.timeout);
if (options.timeout && options.timeout > 0) {
timeoutId = setTimeout(() => reject(new TimeoutError('waitForNextUpdate', options)), options.timeout);
}

@@ -58,3 +57,2 @@

} = {}) => {
// eslint-disable-next-line consistent-return
const checkResult = () => {

@@ -64,6 +62,8 @@ try {

return callbackResult || callbackResult === undefined;
} catch (e) {
} catch (error) {
if (!suppressErrors) {
throw e;
throw error;
}
return undefined;
}

@@ -89,5 +89,5 @@ };

}
} catch (e) {
if (e.timeout) {
throw createTimeoutError('waitFor', {
} catch (error) {
if (error instanceof TimeoutError) {
throw new TimeoutError('waitFor', {
timeout: initialTimeout

@@ -97,6 +97,6 @@ });

throw e;
throw error;
}
timeout -= Date.now() - startTime;
if (timeout) timeout -= Date.now() - startTime;
}

@@ -110,29 +110,3 @@ };

const wait = async (callback, {
timeout,
suppressErrors
} = {}) => {
if (!hasWarnedDeprecatedWait) {
hasWarnedDeprecatedWait = true;
console.warn('`wait` has been deprecated. Use `waitFor` instead: https://react-hooks-testing-library.com/reference/api#waitfor.');
}
try {
await waitFor(callback, {
timeout,
suppressErrors
});
} catch (e) {
if (e.timeout) {
throw createTimeoutError('wait', {
timeout
});
}
throw e;
}
};
return {
wait,
waitFor,

@@ -148,8 +122,8 @@ waitForNextUpdate,

});
} catch (e) {
if (e.timeout) {
throw createTimeoutError('waitForValueToChange', options);
} catch (error) {
if (error instanceof TimeoutError) {
throw new TimeoutError('waitForValueToChange', options);
}
throw e;
throw error;
}

@@ -156,0 +130,0 @@ }

@@ -20,3 +20,3 @@ "use strict";

function addCleanup(callback) {
cleanupCallbacks.unshift(callback);
cleanupCallbacks = [callback, ...cleanupCallbacks];
return () => removeCleanup(callback);

@@ -23,0 +23,0 @@ }

@@ -44,2 +44,6 @@ "use strict";

function isPromise(value) {
return typeof value.then === 'function';
}
function TestHook({

@@ -52,5 +56,6 @@ callback,

try {
// coerce undefined into TProps, so it maintains the previous behaviour
children(callback(hookProps));
} catch (err) {
if (err.then) {
if (isPromise(err)) {
throw err;

@@ -77,3 +82,3 @@ } else {

error
}) => error || value);
}) => error != null ? error : value);
},

@@ -149,6 +154,2 @@

});
const {
unmount,
update
} = testRenderer;

@@ -158,3 +159,3 @@ function unmountHook() {

(0, _cleanup.removeCleanup)(unmountHook);
unmount();
testRenderer.unmount();
});

@@ -169,3 +170,3 @@ }

(0, _reactTestRenderer.act)(() => {
update(toRender());
testRenderer.update(toRender());
});

@@ -172,0 +173,0 @@ },

{
"name": "@testing-library/react-hooks",
"version": "3.7.0",
"version": "4.0.0-beta.1",
"description": "Simple and complete React hooks testing utilities that encourage good testing practices.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"keywords": [

@@ -30,6 +31,7 @@ "testing",

"build": "kcd-scripts build --out-dir lib",
"test": "kcd-scripts test",
"typecheck": "kcd-scripts typecheck",
"lint": "kcd-scripts lint",
"format": "kcd-scripts format",
"coverage": "codecov",
"test": "kcd-scripts test",
"docs:dev": "docz dev",

@@ -41,5 +43,8 @@ "docs:build": "docz build",

"@babel/runtime": "^7.12.5",
"@types/testing-library__react-hooks": "^3.4.0"
"@types/react": ">=16.9.0",
"@types/react-test-renderer": ">=16.9.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"all-contributors-cli": "6.19.0",

@@ -50,7 +55,8 @@ "codecov": "3.8.1",

"docz-utils": "2.3.0",
"eslint": "7.15.0",
"kcd-scripts": "7.5.2",
"prettier": "^2.2.1",
"react": "17.0.1",
"react-test-renderer": "17.0.1",
"typescript": "4.1.2",
"eslint": "7.15.0"
"typescript": "4.1.2"
},

@@ -57,0 +63,0 @@ "peerDependencies": {

@@ -195,2 +195,10 @@ <div align="center">

</tr>
<tr>
<td align="center"><a href="https://github.com/nobrayner"><img src="https://avatars2.githubusercontent.com/u/40751395?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Braydon Hall</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=nobrayner" title="Code">💻</a></td>
<td align="center"><a href="https://dev.to/jacobmgevans"><img src="https://avatars1.githubusercontent.com/u/27247160?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jacob M-G Evans</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=JacobMGEvans" title="Code">💻</a> <a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=JacobMGEvans" title="Tests">⚠️</a></td>
<td align="center"><a href="https://tigerabrodi.dev/"><img src="https://avatars1.githubusercontent.com/u/49603590?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tiger Abrodi</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=tigerabrodi" title="Code">💻</a> <a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=tigerabrodi" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/merodiro"><img src="https://avatars1.githubusercontent.com/u/17033502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Amr A.Mohammed</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=merodiro" title="Code">💻</a> <a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=merodiro" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/juhanakristian"><img src="https://avatars1.githubusercontent.com/u/544386?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Juhana Jauhiainen</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=juhanakristian" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/jensmeindertsma"><img src="https://avatars3.githubusercontent.com/u/64677517?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jens Meindertsma</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=jensmeindertsma" title="Code">💻</a> <a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=jensmeindertsma" title="Tests">⚠️</a></td>
</tr>
</table>

@@ -197,0 +205,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc