This repository has been archived by the owner on Jul 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93b5c34
commit 43185fa
Showing
5 changed files
with
105 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |