x
?describe
and it
)expect(1 + 2).toEqual(3)
)Discuss this
describe('<Button />', () => {
it('should invoke the onClick callback when clicked');
});
Behaviour driven development feels better suited to UI based testing rather than just functional definitions.
const Button = ({
onClick,
text
}) => (
<div onClick={onClick} className="button">
{text}
</div>
)
// Implementation details inside tests
it('should return a <div />', () => {
const tree = shallow(<Button text="Hello World" />);
expect(tree.type()).toEqual('div');
});
it('should show passed text in .button', () => {
const tree = shallow(<Button text="Hello World" />);
const actual = tree.find('.button').text();
expect(actual).toEqual('Hello World');
});
it('should display the passed text prop', () => {
const tree = shallow(<Button text="Hello World" />);
expect(tree.text).toContain("Hello World");
});
it('should invoke onClick prop when clicked', () => {
const spy = jest.fn();
const tree = shallow(
<Button
text="Hello World
onClick={spy} />
);
tree.simulate('click');
expect(spy.calls).toEqual(1);
});
wrapper.simulate('click')
will look for the onClick
prop and invoke that
wrapper.simulate('click', { id: 123 });
const SeatPrefs = ({ willReserve: boolean }) => (
<div>
<h3>Seating Preferences</h3>
{ willReserve && <div>
<SeatSelections />
<SeatLocations />
<SmallNote />
</div> }
</div>
);
☹️
it('should render a Direction selectbox');
it('should render a Position selectbox');
it('should render a CoachType selectbox');
it('should render a Table seat checkbox');
it('should render a Power Socket checkbox');
it('should render a Luggage Rack checkbox');
it('should render a Near Toilet checkbox');
😀
it('should render <SeatSelections /> when willReserve');
it('should render <SeatLocations /> when willReserve');
it('should render <SmallNote /> when willReserve');
SeatSelections
must have it's own testsSeatLocations
must have it's own testsSmallNote
must have it's own tests