Library for testing Welgo components
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.gitignore
.travis.yml
README.md
package-lock.json
package.json

README.md

Weltest

Build Status

Library to test welgo library code.

API

Shallow rendering:

const { createElement } = require('welgo');
const htm = require('htm');
const { shallow } = require('weltest');

const html = htm.bind(createElement);

test('<MyComponent /> renders three <Foo /> components', () => {
  const wrapper = shallow(html`<${MyComponent} />`);
  expect(wrapper.find(Foo)).to.have.lengthOf(3);
});

it('<MyComponent /> renders an `.icon-star`', () => {
  const wrapper = shallow(html`<${MyComponent} />`);
  expect(wrapper.find('.icon-star')).to.have.lengthOf(1);
});

Instead of using shallow, you can use mount method:

const { mount } = require('weltest');

The idea of shallow/full-rendering is taken from enzyme.

Right now wrapper offers only one method – find. If you pass a selector (for querySelector), it will return a list of DOM nodes. If you pass an actual component, it will return an array of wrappers, on which you can find again.

Run

If you want to run tests in this repository, you'll need Node v10+.

npm i
npm t

License

MIT