Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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 5.0.3 to 5.1.0

3

lib/core/console.d.ts

@@ -0,2 +1,3 @@

declare function suppressErrorOutput(): () => void;
declare function enableErrorOutputSuppression(): void;
export { enableErrorOutputSuppression };
export { enableErrorOutputSuppression, suppressErrorOutput };

@@ -9,18 +9,27 @@ "use strict";

exports.enableErrorOutputSuppression = enableErrorOutputSuppression;
exports.suppressErrorOutput = suppressErrorOutput;
var _filterConsole = _interopRequireDefault(require("filter-console"));
function suppressErrorOutput() {
if (process.env.RHTL_DISABLE_ERROR_FILTERING) {
return () => {};
}
return (0, _filterConsole.default)([/^The above error occurred in the <TestComponent> component:/, // error boundary output
/^Error: Uncaught .+/ // jsdom output
], {
methods: ['error']
});
}
function enableErrorOutputSuppression() {
// Automatically registers console error suppression and restoration in supported testing frameworks
if (typeof beforeEach === 'function' && typeof afterEach === 'function' && !process.env.RHTL_DISABLE_ERROR_FILTERING) {
if (typeof beforeEach === 'function' && typeof afterEach === 'function') {
let restoreConsole;
beforeEach(() => {
restoreConsole = (0, _filterConsole.default)([/^The above error occurred in the <TestComponent> component:/, // error boundary output
/^Error: Uncaught .+/ // jsdom output
], {
methods: ['error']
});
restoreConsole = suppressErrorOutput();
});
afterEach(() => restoreConsole == null ? void 0 : restoreConsole());
afterEach(() => restoreConsole());
}
}
import { CreateRenderer, Renderer, RenderResult, RenderHookOptions } from '../types';
import { cleanup, addCleanup, removeCleanup } from './cleanup';
import { suppressErrorOutput } from './console';
declare function createRenderHook<TProps, TResult, TRendererOptions extends object, TRenderer extends Renderer<TProps>>(createRenderer: CreateRenderer<TProps, TResult, TRendererOptions, TRenderer>): (callback: (props: TProps) => TResult, options?: RenderHookOptions<TProps> & TRendererOptions) => {

@@ -10,3 +11,3 @@ waitFor: import("../types").WaitFor;

unmount: () => void;
} & Pick<TRenderer, Exclude<keyof TRenderer, "render" | "act" | "rerender" | "unmount">>;
export { createRenderHook, cleanup, addCleanup, removeCleanup };
} & Omit<TRenderer, "render" | "act" | "rerender" | "unmount">;
export { createRenderHook, cleanup, addCleanup, removeCleanup, suppressErrorOutput };

@@ -25,2 +25,8 @@ "use strict";

});
Object.defineProperty(exports, "suppressErrorOutput", {
enumerable: true,
get: function () {
return _console.suppressErrorOutput;
}
});

@@ -31,2 +37,4 @@ var _asyncUtils = require("./asyncUtils");

var _console = require("./console");
function resultContainer() {

@@ -33,0 +41,0 @@ const results = [];

@@ -10,3 +10,3 @@ import { act } from 'react-dom/test-utils';

unmount: () => void;
} & Pick<{
} & Omit<{
render(props?: TProps | undefined): void;

@@ -16,5 +16,5 @@ rerender(props?: TProps | undefined): void;

act: typeof act;
}, never>;
}, "render" | "act" | "rerender" | "unmount">;
export { renderHook, act };
export { cleanup, addCleanup, removeCleanup } from '../core';
export { cleanup, addCleanup, removeCleanup, suppressErrorOutput } from '../core';
export * from '../types/react';

@@ -13,3 +13,4 @@ "use strict";

addCleanup: true,
removeCleanup: true
removeCleanup: true,
suppressErrorOutput: true
};

@@ -40,2 +41,8 @@ Object.defineProperty(exports, "act", {

});
Object.defineProperty(exports, "suppressErrorOutput", {
enumerable: true,
get: function () {
return _core.suppressErrorOutput;
}
});
exports.renderHook = void 0;

@@ -42,0 +49,0 @@

@@ -10,3 +10,3 @@ import { act } from 'react-test-renderer';

unmount: () => void;
} & Pick<{
} & Omit<{
render(props?: TProps | undefined): void;

@@ -16,5 +16,5 @@ rerender(props?: TProps | undefined): void;

act: typeof act;
}, never>;
}, "render" | "act" | "rerender" | "unmount">;
export { renderHook, act };
export { cleanup, addCleanup, removeCleanup } from '../core';
export { cleanup, addCleanup, removeCleanup, suppressErrorOutput } from '../core';
export * from '../types/react';

@@ -11,3 +11,4 @@ "use strict";

addCleanup: true,
removeCleanup: true
removeCleanup: true,
suppressErrorOutput: true
};

@@ -38,2 +39,8 @@ Object.defineProperty(exports, "act", {

});
Object.defineProperty(exports, "suppressErrorOutput", {
enumerable: true,
get: function () {
return _core.suppressErrorOutput;
}
});
exports.renderHook = void 0;

@@ -40,0 +47,0 @@

@@ -1,3 +0,3 @@

declare const renderHook: <TProps, TResult>(callback: (props: TProps) => TResult, options?: import("./types/react").RenderHookOptions<TProps> | undefined) => import("./types").RenderHookResult<TProps, TResult, import("./types").Renderer<TProps>>, act: import("./types").Act, cleanup: () => void, addCleanup: (callback: import("./types").CleanupCallback) => () => void, removeCleanup: (callback: import("./types").CleanupCallback) => void;
export { renderHook, act, cleanup, addCleanup, removeCleanup };
declare const renderHook: <TProps, TResult>(callback: (props: TProps) => TResult, options?: import("./types/react").RenderHookOptions<TProps> | undefined) => import("./types").RenderHookResult<TProps, TResult, import("./types").Renderer<TProps>>, act: import("./types").Act, cleanup: () => void, addCleanup: (callback: import("./types").CleanupCallback) => () => void, removeCleanup: (callback: import("./types").CleanupCallback) => void, suppressErrorOutput: () => () => void;
export { renderHook, act, cleanup, addCleanup, removeCleanup, suppressErrorOutput };
export * from './types/react';

@@ -11,5 +11,6 @@ "use strict";

addCleanup: true,
removeCleanup: true
removeCleanup: true,
suppressErrorOutput: true
};
exports.removeCleanup = exports.addCleanup = exports.cleanup = exports.act = exports.renderHook = void 0;
exports.suppressErrorOutput = exports.removeCleanup = exports.addCleanup = exports.cleanup = exports.act = exports.renderHook = void 0;

@@ -68,4 +69,6 @@ var _react = require("./types/react");

addCleanup,
removeCleanup
removeCleanup,
suppressErrorOutput
} = getRenderer();
exports.suppressErrorOutput = suppressErrorOutput;
exports.removeCleanup = removeCleanup;

@@ -72,0 +75,0 @@ exports.addCleanup = addCleanup;

@@ -10,3 +10,3 @@ import { act } from 'react-dom/test-utils';

unmount: () => void;
} & Pick<{
} & Omit<{
render(props?: TProps | undefined): void;

@@ -17,5 +17,5 @@ hydrate(): void;

act: typeof act;
}, "hydrate">;
}, "render" | "act" | "rerender" | "unmount">;
export { renderHook, act };
export { cleanup, addCleanup, removeCleanup } from '../core';
export { cleanup, addCleanup, removeCleanup, suppressErrorOutput } from '../core';
export * from '../types/react';

@@ -13,3 +13,4 @@ "use strict";

addCleanup: true,
removeCleanup: true
removeCleanup: true,
suppressErrorOutput: true
};

@@ -40,2 +41,8 @@ Object.defineProperty(exports, "act", {

});
Object.defineProperty(exports, "suppressErrorOutput", {
enumerable: true,
get: function () {
return _core.suppressErrorOutput;
}
});
exports.renderHook = void 0;

@@ -42,0 +49,0 @@

@@ -16,3 +16,4 @@ import { ComponentType } from 'react';

removeCleanup: (callback: CleanupCallback) => void;
suppressErrorOutput: () => () => void;
};
export * from '.';
{
"name": "@testing-library/react-hooks",
"version": "5.0.3",
"version": "5.1.0",
"description": "Simple and complete React hooks testing utilities that encourage good testing practices.",

@@ -56,3 +56,3 @@ "main": "lib/index.js",

"@typescript-eslint/parser": "^4.9.1",
"all-contributors-cli": "6.19.0",
"all-contributors-cli": "6.20.0",
"codecov": "3.8.1",

@@ -62,4 +62,4 @@ "docz": "2.3.1",

"docz-utils": "2.3.0",
"eslint": "7.18.0",
"kcd-scripts": "7.5.5",
"eslint": "7.21.0",
"kcd-scripts": "7.7.0",
"prettier": "^2.2.1",

@@ -70,3 +70,3 @@ "react": "17.0.1",

"ts-node": "^9.1.1",
"typescript": "4.1.3"
"typescript": "4.2.2"
},

@@ -73,0 +73,0 @@ "peerDependencies": {

@@ -45,2 +45,3 @@ <div align="center">

- [The problem](#the-problem)

@@ -237,2 +238,5 @@ - [The solution](#the-solution)

</tr>
<tr>
<td align="center"><a href="https://seanbaines.com/"><img src="https://avatars.githubusercontent.com/u/24367010?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sean Baines</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=mrseanbaines" title="Documentation">📖</a></td>
</tr>
</table>

@@ -239,0 +243,0 @@

import filterConsole from 'filter-console'
function suppressErrorOutput() {
if (process.env.RHTL_DISABLE_ERROR_FILTERING) {
return () => {}
}
return filterConsole(
[
/^The above error occurred in the <TestComponent> component:/, // error boundary output
/^Error: Uncaught .+/ // jsdom output
],
{
methods: ['error']
}
)
}
function enableErrorOutputSuppression() {
// Automatically registers console error suppression and restoration in supported testing frameworks
if (
typeof beforeEach === 'function' &&
typeof afterEach === 'function' &&
!process.env.RHTL_DISABLE_ERROR_FILTERING
) {
let restoreConsole: () => void
if (typeof beforeEach === 'function' && typeof afterEach === 'function') {
let restoreConsole!: () => void
beforeEach(() => {
restoreConsole = filterConsole(
[
/^The above error occurred in the <TestComponent> component:/, // error boundary output
/^Error: Uncaught .+/ // jsdom output
],
{
methods: ['error']
}
)
restoreConsole = suppressErrorOutput()
})
afterEach(() => restoreConsole?.())
afterEach(() => restoreConsole())
}
}
export { enableErrorOutputSuppression }
export { enableErrorOutputSuppression, suppressErrorOutput }

@@ -5,2 +5,3 @@ import { CreateRenderer, Renderer, RenderResult, RenderHookOptions } from '../types'

import { cleanup, addCleanup, removeCleanup } from './cleanup'
import { suppressErrorOutput } from './console'

@@ -85,2 +86,2 @@ function resultContainer<TValue>() {

export { createRenderHook, cleanup, addCleanup, removeCleanup }
export { createRenderHook, cleanup, addCleanup, removeCleanup, suppressErrorOutput }

@@ -8,6 +8,6 @@ // This verifies that if RHTL_DISABLE_ERROR_FILTERING is set

process.env.RHTL_DISABLE_ERROR_FILTERING = 'true'
require('..')
})
test('should not patch console.error', () => {
require('..')
expect(console.error).toBe(originalConsoleError)

@@ -14,0 +14,0 @@ })

@@ -0,1 +1,3 @@

import { ReactHooksRenderer } from '../../types/react'
// This verifies that if pure imports are used

@@ -6,4 +8,6 @@ // then we DON'T auto-wire up the afterEach for folks

let suppressErrorOutput!: ReactHooksRenderer['suppressErrorOutput']
beforeAll(() => {
require('../pure')
suppressErrorOutput = (require('../pure') as ReactHooksRenderer).suppressErrorOutput
})

@@ -14,4 +18,14 @@

})
test('should manually patch console.error', () => {
const restore = suppressErrorOutput()
try {
expect(console.error).not.toBe(originalConsoleError)
} finally {
restore()
}
expect(console.error).toBe(originalConsoleError)
})
})
export {}

@@ -40,4 +40,4 @@ import ReactDOM from 'react-dom'

export { cleanup, addCleanup, removeCleanup } from '../core'
export { cleanup, addCleanup, removeCleanup, suppressErrorOutput } from '../core'
export * from '../types/react'

@@ -8,6 +8,6 @@ // This verifies that if RHTL_DISABLE_ERROR_FILTERING is set

process.env.RHTL_DISABLE_ERROR_FILTERING = 'true'
require('..')
})
test('should not patch console.error', () => {
require('..')
expect(console.error).toBe(originalConsoleError)

@@ -14,0 +14,0 @@ })

@@ -0,1 +1,3 @@

import { ReactHooksRenderer } from '../../types/react'
// This verifies that if pure imports are used

@@ -6,4 +8,6 @@ // then we DON'T auto-wire up the afterEach for folks

let suppressErrorOutput!: ReactHooksRenderer['suppressErrorOutput']
beforeAll(() => {
require('../pure')
suppressErrorOutput = (require('../pure') as ReactHooksRenderer).suppressErrorOutput
})

@@ -14,4 +18,14 @@

})
test('should manually patch console.error', () => {
const restore = suppressErrorOutput()
try {
expect(console.error).not.toBe(originalConsoleError)
} finally {
restore()
}
expect(console.error).toBe(originalConsoleError)
})
})
export {}

@@ -39,4 +39,4 @@ import { act, create, ReactTestRenderer } from 'react-test-renderer'

export { cleanup, addCleanup, removeCleanup } from '../core'
export { cleanup, addCleanup, removeCleanup, suppressErrorOutput } from '../core'
export * from '../types/react'

@@ -35,6 +35,6 @@ import { ReactHooksRenderer } from './types/react'

const { renderHook, act, cleanup, addCleanup, removeCleanup } = getRenderer()
const { renderHook, act, cleanup, addCleanup, removeCleanup, suppressErrorOutput } = getRenderer()
export { renderHook, act, cleanup, addCleanup, removeCleanup }
export { renderHook, act, cleanup, addCleanup, removeCleanup, suppressErrorOutput }
export * from './types/react'

@@ -8,6 +8,6 @@ // This verifies that if RHTL_DISABLE_ERROR_FILTERING is set

process.env.RHTL_DISABLE_ERROR_FILTERING = 'true'
require('..')
})
test('should not patch console.error', () => {
require('..')
expect(console.error).toBe(originalConsoleError)

@@ -14,0 +14,0 @@ })

@@ -0,1 +1,3 @@

import { ReactHooksRenderer } from '../../types/react'
// This verifies that if pure imports are used

@@ -6,4 +8,6 @@ // then we DON'T auto-wire up the afterEach for folks

let suppressErrorOutput!: ReactHooksRenderer['suppressErrorOutput']
beforeAll(() => {
require('../pure')
suppressErrorOutput = (require('../pure') as ReactHooksRenderer).suppressErrorOutput
})

@@ -14,4 +18,14 @@

})
test('should manually patch console.error', () => {
const restore = suppressErrorOutput()
try {
expect(console.error).not.toBe(originalConsoleError)
} finally {
restore()
}
expect(console.error).toBe(originalConsoleError)
})
})
export {}

@@ -64,4 +64,4 @@ import ReactDOMServer from 'react-dom/server'

export { cleanup, addCleanup, removeCleanup } from '../core'
export { cleanup, addCleanup, removeCleanup, suppressErrorOutput } from '../core'
export * from '../types/react'

@@ -29,4 +29,5 @@ import { ComponentType } from 'react'

removeCleanup: (callback: CleanupCallback) => void
suppressErrorOutput: () => () => void
}
export * from '.'
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