Skip to content

Commit

Permalink
Added tests for mithril (#11)
Browse files Browse the repository at this point in the history
I've used a `wait` in the tests because mithril renders on nextTick. I'm unsure if this is the right way to test it though.
  • Loading branch information
karthikiyengar authored and Kent C. Dodds committed Sep 17, 2018
1 parent 3e1c1d4 commit abfafba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
33 changes: 33 additions & 0 deletions mithril.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'jest-dom/extend-expect'
import m from 'mithril'
import {getQueriesForElement, fireEvent, wait} from 'dom-testing-library'

const Counter = () => {
let count = 0
return {
view: () =>
m(
'button',
{
onclick: () => {
count++
},
},
count,
),
}
}

// tests:
test('counter increments', async () => {
const div = document.createElement('div')
m.mount(div, Counter)

const {getByText} = getQueriesForElement(div)
const counter = getByText('0')
fireEvent.click(counter)
await wait(() => expect(counter).toHaveTextContent('1'))

fireEvent.click(counter)
await wait(() => expect(counter).toHaveTextContent('2'))
})
5 changes: 5 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"hyperapp": "^1.2.9",
"jquery": "^3.3.1",
"knockout": "^3.4.2",
"mithril": "^1.1.6",
"preact": "^8.3.1",
"react": "^16.5.1",
"stimulus": "^1.1.0",
Expand Down

0 comments on commit abfafba

Please sign in to comment.