jest-plugin-context
Adds context
as an alternative to describe
for jest.
Getting Started
Install jest-plugin-context
using yarn
:
yarn add --dev jest-plugin-context
Motivation
RSpec took the ruby world by storm with its declarative method of TDD. In RSpec, describe
it used to wrap a set of tests against one functionality while context
is to wrap a set of tests against one functionality under the same state.
The difference being you should only describe
to test the User model and specifically describe
the #name
method. However, testing different states of the #name
method should use different context. You can view an example of this below.
Usage
If you want, you can import context
from jest-plugin-context
at the top of every test:
;
If you want to install context
as a global, you can modify the jest
section of your package.json
to include:
"jest":
Example
Here's an example test that uses context
:
;