sample in JS
portion of package.json
"dependencies": {
"enzyme": "^3.6.0",
"enzyme-adapter-react-16": "^1.5.0",
SetupTests.js
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
simple component
import React from "react";
export default class Scoreboard extends React.Component {
render() {
return (
<div>
<ul>
<li> Score 1 </li>
<li> Score 2 </li>
</ul>
</div>);
};
}
The test
import { shallow } from 'enzyme';
import Scoreboard from "./scoreboard"
it('renders finds 2 scores', () => {
const mountedScoreboard = shallow(<Scoreboard />);
const scores = mountedScoreboard.find("li");
expect(scores.length).toBe(2);
});
it('first score value is correct', () => {
const mountedScoreboard = shallow(<Scoreboard />);
const scores = mountedScoreboard.find("li");
expect(scores.first().text()).toBe(" Score 1 ");
});