From c59b5c17a429f1d2b86580c88f3e79e2ca1ba763 Mon Sep 17 00:00:00 2001 From: Levi Thomason Date: Sat, 16 Jul 2016 08:41:17 -0700 Subject: [PATCH] test(Checkbox): add onChange test --- src/modules/Checkbox/Checkbox.js | 17 ++++++------- test/specs/modules/Checkbox/Checkbox-test.js | 25 +++++++++++++++++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/modules/Checkbox/Checkbox.js b/src/modules/Checkbox/Checkbox.js index 4690b80be4..85966f7c1e 100644 --- a/src/modules/Checkbox/Checkbox.js +++ b/src/modules/Checkbox/Checkbox.js @@ -112,10 +112,6 @@ export default class Checkbox extends AutoControlledComponent { render() { const { className, inputType, label, name, onChange, type, value } = this.props const { checked } = this.state - debug('render()') - debug(` name: ${name}`) - debug(` value: ${value}`) - debug(` checked: ${checked}`) const classes = cx( 'ui', // don't add duplicate "checkbox" classes, but add any other type @@ -128,21 +124,22 @@ export default class Checkbox extends AutoControlledComponent { className ) const rest = getUnhandledProps(Checkbox, this.props) + // Heads Up! + // onChange props are never called as the user cannot click on the hidden input. + // We call onChange in the onClick handler. + // This exists only to prevent React "prop checked without onChange" warnings. return ( - // Heads Up! - // onChange is never called because the user cannot click on the hidden input. - // We call onChange in the onClick handler. - // This exists only to prevent React "prop checked without onChange" warnings.
{ describe('defaultChecked', () => { it('sets the initial checked state', () => { // consoleUtil.disableOnce() - shallow() + shallow() .find('input') .should.be.checked() }) @@ -88,13 +88,32 @@ describe('Checkbox', () => { }) describe('onClick', () => { - it('is called on label click', () => { + it('is called with (event { name, value, checked }) on label click', () => { const spy = sandbox.spy() - mount() + const expectProps = { name: 'foo', value: 'bar', checked: false } + mount() .find('label') .simulate('click') spy.should.have.been.calledOnce() + spy.should.have.been.calledWithMatch({}, {}) + spy.firstCall.args[1] + .should.deep.equal(expectProps) + }) + }) + + describe('onChange', () => { + it('is called with (event { name, value, !checked }) on click', () => { + const spy = sandbox.spy() + const expectProps = { name: 'foo', value: 'bar', checked: false } + mount() + .find('label') + .simulate('click') + + spy.should.have.been.calledOnce() + spy.should.have.been.calledWithMatch({}, {}) + spy.firstCall.args[1] + .should.deep.equal({ ...expectProps, checked: true }) }) })