Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CheckboxGroup tests to use process.nextTick() #721

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/components/adslot-ui/CheckboxGroup/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ describe('CheckboxGroup', () => {
<Checkbox label="The Sound of Music" value="soundofmusic" />
</CheckboxGroup>
);

const childCheckboxes = component.find('Checkbox');
const firstChild = childCheckboxes.at(0);
const event = { target: { value: 'terminator', checked: false } };
const event = { target: { value: 'terminator' } };
firstChild.simulate('change', event);
expect(component.state().value).to.eql({ terminator: false, predator: true, soundofmusic: false });
process.nextTick(() => {
expect(component.state().value).to.eql({ terminator: false, predator: true, soundofmusic: false });
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to pass in done() to ensure that the test will finish after nextTick() is executed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good pickup man

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I do that, the test fails... go figure.

expect(onChangeGroup.callCount).to.equal(1);
expect(onChangeIndividual.callCount).to.equal(1);
});
Expand All @@ -54,7 +55,7 @@ describe('CheckboxGroup', () => {
});

it('should handle change events without a custom onChange handler', () => {
const event = { target: { value: 'terminator', checked: true } };
const event = { target: { value: 'terminator' } };
const component = shallow(
<CheckboxGroup name="movies">
<Checkbox label="The Terminator" value="terminator" />
Expand All @@ -64,7 +65,9 @@ describe('CheckboxGroup', () => {
);
const firstChild = component.find('Checkbox').at(0);
firstChild.simulate('change', event);
expect(component.state().value).to.eql({ terminator: true, predator: false, soundofmusic: false });
process.nextTick(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is a good retro learned to add and talk about

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(component.state().value).to.eql({ terminator: true, predator: false, soundofmusic: false });
});
});

it('should handle props changes', () => {
Expand Down