:construction: Note: This package is still very experimental. Expect frequent, breaking changes right up until 1.0 is released. :construction:
shallow
API is implementedsimulate
method is currently wrapped in multiple simulateN
functions
to handle mixed variadic argumentsrender
nor mount
APIs are implementedUsing the excellent bs-jest
open Jest;
Enzyme.configureEnzyme(Enzyme.react_16_adapter());
let setup = (~title="Test", ~handleClick=(_evt) => (), ()) =>
Enzyme.shallow(<DummyComponent title handleClick />);
let header = (wrapper) =>
wrapper
|> Enzyme.find("#header")
|> Enzyme.first;
let listItems = (wrapper) =>
wrapper
|> Enzyme.find("#list")
|> Enzyme.children;
describe("DummyComponent", () => {
open Expect;
test("renders a #header", () => {
let title = "A test title";
let wrapper = setup(~title, ());
let headerNodes = wrapper |> header;
expect(Enzyme.length(headerNodes)) |> toBe(1)
});
test("has the expected h1 tag in the #header", () => {
let title = "A test title";
let wrapper = setup(~title, ());
let expectedNode = <h1> (ReasonReact.stringToElement(title)) </h1>;
expect(Enzyme.contains(expectedNode, wrapper)) |> toBe(true)
});
test("initially has its `clicked` state set to false", () => {
let wrapper = setup();
let {clicked}: DummyComponent.state = Enzyme.state(wrapper);
expect(clicked) |> toBe(false)
});
test("folds left properly", () => {
let items = setup() |> listItems;
let result = Enzyme.foldLeft((text, node) => text ++ Enzyme.text(node), "", items);
expect(result) |> toBe("OneTwoThree")
});
});
See more examples in the project's tests directory.
$ npm install --save-dev bs-enzyme
Then add bs-enzyme
to bs-dev-dependencies
in your bsconfig.json
:
{
...
"bs-dev-dependencies": ["bs-enzyme"]
}
Note: If you're using this package with bs-jest
, be sure to list
bs-enzyme
first in your dependencies.