bs-enzyme - BuckleScript bindings for Enzyme
๐ง Note: This package is still very experimental. Expect frequent, breaking changes right up until 1.0 is released. ๐ง
- Most of the
shallow
API is implemented - The
simulate
method is currently wrapped in multiplesimulateN
functions to handle mixed variadic arguments - Neither the
render
normount
APIs are implemented - I haven't extensively tested most of the functions, so some might be broken
Using the excellent bs-jest
open Jest;
let setup ::title="Test" ::handleClick=(fun _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" (fun () => {
open Expect;
test "renders a #header" (fun () => {
let title = "A test title";
let wrapper = setup title::title ();
let headerNodes = wrapper |> header;
expect (Enzyme.length headerNodes) |> toBe 1;
});
test "has the expected h1 tag in the #header" (fun () => {
let title = "A test title";
let wrapper = setup title::title ();
let expectedNode = <h1>(ReasonReact.stringToElement title)</h1>;
expect (Enzyme.contains expectedNode wrapper) |> toBe true;
});
test "initially has its `clicked` state set to false" (fun () => {
let wrapper = setup ();
let { clicked }: DummyComponent.state = Enzyme.state wrapper;
expect clicked |> toBe false;
});
test "folds left properly" (fun () => {
let items = setup () |> listItems;
let result = Enzyme.foldLeft (fun 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.