Legit Tests
This is a super friendly testing library for React, inspired by express middleware, it's easily extendable. Why did I make this when you can use React's Test Utils? Because who likes typing out scryRenderedDOMComponentsWithTag
and the other method names on there. Not only that, but setting up the render process is also a hassle.
Install
npm install legit-tests --save
Example
//or let spy = sinon //Calling a prop //finding an elementelements'.box' { tobe}
Middleware
You can write middleware to do anything you repeatedly use. You can pass .use
a function, along with an object that it will take in. Each function will be injected with the current instance which includes:
component
- the actual component itselfinstance
- the rendered component instancehelpers
- an array you can add on to with data for the end function
Example:
- See
mixin
below, this syntax may soon be deprecated
This is the setState function used above.
... { thisinstance}
test
The .test
function will be given the component instance and the helpers array. You can use a regular function to reference this
or an arrow function:
element
Use .element
if you're just testing an element you found with the .find
method. The syntax is a little smaller:
//or specify the element
mixin
Use .mixin
if you want to add new middleware as methods to Test
. This gives a more natural way of using middleware:
// In this example, CustomFind middleware was added to Test by mixin// and used if as it was a method on Test itself.
DOM rendering
Shallow -- uses React shallow rendering (no DOM)
Normal -- React render into document fragment
fullDOM -- ReactDOM render into document.body.div of jsdom
// restores the document.body to empty
You can see more examples in the tests directory.
Testing Alt Stores
You can now test Alt stores using the same API.
You can see the full documentation on the Wiki