-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Adds basic Toolbar component tests. #937
Conversation
f4cca21
to
425fca0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on these tests 👍
components/toolbar/test/index.js
Outdated
const toolbar = shallow( <Toolbar controls={ controls } /> ); | ||
const listItem = toolbar.find( 'IconButton' ); | ||
expect( toolbar.type() ).to.equal( 'ul' ); | ||
expect( listItem.props().icon ).to.equal( 'wordpress' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: listItem.prop( 'icon' )
more explicit. Same goes for most of the following lines. Else we could test:
expect( listItem.props() ).to.eql( {
// ...keys
} );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought I updated these, guess not lol. Will change. Should it be changed to the one command style?
expect( listItem.props() ).to.eql( {
// ...keys
} );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a preference.
components/toolbar/test/index.js
Outdated
const toolbar = shallow( <Toolbar controls={ controls } /> ); | ||
const listItem = toolbar.find( 'IconButton' ); | ||
listItem.simulate( 'click', { stopPropagation: () => undefined } ); | ||
expect( clicked ).to.be.true(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sinon spies are great for this sort of test:
http://sinonjs.org/releases/v2.3.2/spies/
Appears we're now using sinon-test
as of #924, so it'd be matter of:
it( 'should call the clickHandler on click.', sinon.test( function() {
const clickHandler = this.spy();
// ...
expect( clickHandler ).to.have.been.calledOnce;
} );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I realized sinon was being used in our effects tests, so I will use that here as well in the revisions.
Adds basic Toolbar component tests. Related to progress on #641. **Testing Instructions** Run npm i && npm run test-unit ensure tests pass. Change component logic to ensure tests fail as they should.
425fca0
to
8f5c615
Compare
Cleans up the tests to make use of spies. This also changes the `props()` convention to check whether the keys are included in the object. include is used instead of equal to ensure that the tests do not look at all props like children. Adds in a correction to the function signature of Toolbar so that the component renders properly.
8f5c615
to
24e56e9
Compare
@iseulde If you could take a peek at this to make sure this aligns with the changes you made in the Toolbar component, it would be appreciated. |
Adds basic Toolbar component tests. Related to progress on #641.
Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change component logic
to ensure tests fail as they should.