ivi-jest
TypeScript icon, indicating that this package has built-in type declarations

0.27.0 • Public • Published

ivi-jest provides a collection of useful tools for testing with Jest.

Motivation

Jest resets global state for every test module, but all tests in a test module share the same global state. This package provides a set of tools to make it easier to write isolated unit tests.

Configuration

jest.resetModules should be enabled.

Environments

  • ivi-jest/env/jsdom

API

DOM

useResetDOMGlobalEventListeners() tracks event handlers for a window and document objects and removes them after each test.

useResetDOM() enables following resets:

  • useResetDOMGlobalEventListeners()

useDOMElement() creates a DOM element and optionally mounts it to the document body.

useRequestAnimationFrame() mocks requestAnimationFrame() and cancelAnimationFrame().

Modules

useResetModules() resets modules before each test.

useModule() imports module before each test.

Mock

useMockFn() creates a mock function and resets it after each test.

useSpyOn() creates a spy object and resets it after each test.

Environment

useEnv() overrides process.env before each tests and restores to the original value after each test.

Promise

usePromiseQueue() adds support for waiting until promise tasks are executed.

Timers

useTimers() mocks timers.

Computed Value

useComputedValue() creates a value that will be recomputed before each test.

Readme

Keywords

Package Sidebar

Install

npm i ivi-jest

Weekly Downloads

0

Version

0.27.0

License

MIT

Unpacked Size

36.3 kB

Total Files

39

Last publish

Collaborators

  • localvoid