Skip to content

Commit 6137d41

Browse files
committed
[WiP] add test for "main" view #51
1 parent dd51dcb commit 6137d41

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Diff for: todo-list.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,29 @@ which is _checked_ (`done=true`)
786786
that are _unchecked_ (`done=false`)
787787

788788

789-
We can _easily_ write a _test_ that includes these 3 assertions:
790-
789+
We can _easily_ write a _test_ that includes these 3 assertions.
790+
Append following test code to your `test/todo-app.test.js` file:
791791

792+
```js
793+
test('render "main" view using (elmish) HTML DOM functions', function (t) {
794+
const model = {
795+
todos: [
796+
{ id: 1, title: "Learn Elm Architecture", done: true },
797+
{ id: 2, title: "Build Todo List App", done: false },
798+
{ id: 3, title: "Win the Internet!", done, false }
799+
],
800+
hash: '#/' // the "route" to display
801+
};
802+
const html = app.main(model);
803+
804+
const done = document.querySelectorAll('.completed')[0].textContent;
805+
t.equal(done, 'Learn Elm Architecture', 'Done: Learn "TEA"');
806+
const todo = document.querySelectorAll('.view')[1].textContent;
807+
t.equal(todo, 'Build Todo List App', 'Todo: Build Todo List App');
808+
elmish.empty(document.getElementById(id));
809+
t.end();
810+
});
811+
```
792812

793813

794814

0 commit comments

Comments
 (0)