Unit -Tests für React
The testing ecosystem are Jest and Testing Library but mocha works.
CharllierJr
The testing ecosystem are Jest and Testing Library but mocha works.
# Given a component
import React from 'react';
const Hi = ({ userName }) => (
<div className="sayhello">Howdy, {userName}!</div>
);
export default Hi;
# Install required deps
npm install --save-dev riteway
# Unit test
import React from 'react';
import { describe } from 'riteway';
import render from 'riteway/render-component';
import match from 'riteway/match';
import Hi from '../hi';
describe('Hi component', async assert => {
const userName = 'MeMyself';
const $ = render(<Hello userName={userName} />);
const contains = match($('.sayhello').html());
assert({
given: 'A user',
should: 'It should render a correct username.',
actual: contains(userName),
expected: `Hi, ${userName}!`
});
});