Skip to content
This repository has been archived by the owner on Jul 8, 2021. It is now read-only.

Commit

Permalink
add some basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysforyou committed Aug 29, 2017
1 parent 93b5c34 commit 43185fa
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 18 deletions.
7 changes: 4 additions & 3 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "bs-jest",
"name": "bs-enzyme",
"reason": { "react-jsx": 2 },
"bs-dependencies": ["reason-react"],
"bs-dev-dependencies": ["bs-jest", "bs-enzyme"],
"bs-dev-dependencies": ["bs-jest"],
"bsc-flags": ["-bs-super-errors"],
"sources": [{ "dir": "src" }]
"sources": [{ "dir": "src" }, { "dir": "src/__tests__", "type": "dev" }]
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 7 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
"version": "0.1.1",
"description": "Bucklescript bindings for Enzyme",
"scripts": {
"test": "jest",
"build": "bsb -make-world"
"test": "jest --watch",
"build": "bsb -make-world",
"watch": "bsb -make-world -w",
"clean": "bsb -clean-world"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rpowelll/bs-enzyme.git"
},
"keywords": [
"bucklescript",
"enzyme",
"testing"
],
"keywords": ["bucklescript", "enzyme", "testing"],
"author": "Rhys Powell",
"license": "MIT",
"bugs": {
Expand All @@ -25,6 +23,7 @@
"bs-jest": "^0.1.0",
"bs-platform": "^1.9.1",
"jest": "^20.0.4",
"react": "^15.6.1",
"reason-react": "^0.2.3"
},
"dependencies": {
Expand All @@ -37,13 +36,6 @@
"bs-platform": ">=1.9.0"
},
"jest": {
"moduleFileExtensions": [
"re",
"js",
"ml"
],
"testMatch": [
"lib/js/src/**/*_test.re"
]
"testMatch": ["**/src/**/*_test.js"]
}
}
24 changes: 24 additions & 0 deletions src/__tests__/DummyComponent.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
type state = {
clicked: bool
};
let se = ReasonReact.stringToElement;
let component = ReasonReact.statefulComponent "DummyComponent";

let make title::title handleClick::handleClick _children => {
...component,
initialState: fun () => {
clicked: false
},
render: fun {state} => {
<div className="dummy">
<div id="header">
<h1>(se title)</h1>
</div>
<div id="content">
<button id="click-me" onClick=handleClick>
(se (state.clicked ? "I've been clicked!" : "Click Me!"))
</button>
</div>
</div>
}
}
57 changes: 57 additions & 0 deletions src/__tests__/DummyComponent_test.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
open Jest;

let setup ::title="Test" ::handleClick=(fun _evt => ()) () =>
Enzyme.shallow <DummyComponent title handleClick />;

let header wrapper =>
wrapper
|> Enzyme.find "#header"
|> Enzyme.first;

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 title in the #header" (fun () => {
let title = "A test title";
let wrapper = setup title::title ();
let headerText = wrapper |> header |> Enzyme.text;

expect headerText |> toContainString title;
});

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 "has the expected #header" (fun () => {
let title = "A test title";
let wrapper = setup title::title ();
let header = header wrapper;
let expectedNode = <div id="header">
<h1>(ReasonReact.stringToElement title)</h1>
</div>;

expect (Enzyme.equals expectedNode header) |> toBe true;
});

test "has the expected initialState" (fun () => {
let title = "A test title";
let wrapper = setup title::title ();
let state = Enzyme.state wrapper;
Js.log state;

expect state##reasonState |> toContain 0;
});
});

0 comments on commit 43185fa

Please sign in to comment.