Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stephanhoyer/mithril-test
test your mithril modules in a real browser
https://github.com/stephanhoyer/mithril-test
Last synced: 3 months ago
JSON representation
test your mithril modules in a real browser
- Host: GitHub
- URL: https://github.com/stephanhoyer/mithril-test
- Owner: StephanHoyer
- License: mit
- Created: 2018-03-23T23:01:54.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T11:34:14.000Z (about 1 year ago)
- Last Synced: 2024-04-13T22:24:42.004Z (9 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mithril-test
test your mithril modules in a real browser[![Build Status](https://travis-ci.org/StephanHoyer/mithril-test.svg?branch=master)](https://travis-ci.org/StephanHoyer/mithril-test)
## Example usage
Let's say you have the following component:
```js
// myModule.js
const m = require('mithril')module.exports = {
showParagraph: true,
inputValue: '',
view: ({ state }) => [
m('button', {
onclick: () => {
state.showParagraph = false
setTimeout(() => {
state.showParagraph = true
m.redraw()
}, 10)
},
}),
m('input', { oninput: e => (state.inputValue = e.target.value) }),
m('div', state.inputValue),
state.showParagraph && m('p', 'my paragraph'),
],
}
```... you can test its functionality like this:
```js
// myModule.test.js
const load = require('mithril-test')describe('myModule', () => {
it('should work', () => {
return load('./myModule')
.shouldHave('p')
.shouldHave(1, 'p')
.shouldNotHave(2, 'p')
.shouldNotHave('h3')
.shouldNotContain('fancy stuff')
.setValue('input', 'fancy stuff')
.shouldContain('fancy stuff')
.waitFor(100)
.click('button')
.shouldNotHave('p')
.waitFor('p')
.shouldHave('p')
.run()
})
})
```Whole test takes about 600ms.