Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dekujs/component-mock
A helper wrapper used for unit-testing deku components
https://github.com/dekujs/component-mock
Last synced: 3 months ago
JSON representation
A helper wrapper used for unit-testing deku components
- Host: GitHub
- URL: https://github.com/dekujs/component-mock
- Owner: dekujs
- License: mit
- Created: 2015-08-20T18:11:56.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-03T01:09:51.000Z (almost 9 years ago)
- Last Synced: 2024-07-06T04:12:42.564Z (4 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
- awesome-deku - component-mock - A wrapper for deku components to facilitate easier unit-testing. (Testing)
README
# component-mock
> A wrapper for deku components to facilitate easier unit-testing.
## Usage
```js
var Mock = require('component-mock');var Component = {
defaultProps: {
name: 'a'
},
render: function ({ props }) {
return{props.name};
}
}var mock = Mock(Component);
var node = mock.render();
assert.isNode(node, 'div');
assert.hasChildren(node, [ 'a' ]);var node = mock.render({ props: { name: 'b' } });
assert.isNode(node, 'div');
assert.hasChildren(node, [ 'b' ]);
```## Mock(Component)
Returns a wrapper object for the `Component`. The goal is that there will be
many methods that reflect various lifecycle events for the deku component.
Currently, we only deal with `render`, but others will be added over time as
we develop good testing strategies.## mock.render(component)
Calls `Component.render()`. The render function will have all the parameters
it would normally expect generated automatically. (eg: `props`,
`props.children` and `state`)This also uses `Component.defaultProps` and `Component.initialState()` to ensure
the `component` object is generated accurately.The `setState` function that is passed is simply a no-op, it won't trigger any
other changes. (as it shouldn't, since this is designed for unit-testing)