-
Notifications
You must be signed in to change notification settings - Fork 2
Test Blocks
licarm edited this page Jan 20, 2021
·
15 revisions
Code block types are important for how the tests are organized. Below are descriptions of the different test block types:
describe
blocks are methods used for grouping any number of tests, which are run via it
or test
methods.
The format of a describe block is as follows:
describe('name of describe block test', () => {
it('name of it block test', () => {
test body
});
it('name of it block test', () => {
test body
});
it('name of it block test', () => {
test body
});
});
An it block is a test case. Structure it
blocks by following these conventions, where each step is separated by one blank line:
- Test setup all together
- Test action(s) all together
- Test assertions all together
// bad example
it('invokes onClick handler when clicked', () => {
const handler = jest.fn();
const wrapper = mount(<Chip onClick={handler} />);
wrapper.find("Chip").simulate("click");
expect(handler).toHaveBeenCalledTimes(1);
});
// good example
it('invokes onClick handler when clicked', () => {
const handler = jest.fn();
const wrapper = mount(<Chip onClick={handler} />);
wrapper.find('Chip').simulate('click');
expect(handler).toHaveBeenCalledTimes(1);
});