diff options
author | Simon Fondrie-Teitler <simonft@riseup.net> | 2017-05-24 21:30:46 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2017-08-08 18:53:18 -0400 |
commit | 7c9581a656dd1e01d8960bd278d29066af3ec560 (patch) | |
tree | 30e0971c0c1dc116fb6ad8ebc2ef813b53a7d1c4 /ui/test | |
parent | ba70a1090637e1400bf9d59f077a0fd871c2a672 (diff) |
[refactor] use sinon in confirmation component test
This refactors the confirmation component to use sinon instead of
manually checking the the result of calling a function.
Diffstat (limited to 'ui/test')
-rw-r--r-- | ui/test/components/confirmation.js | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/ui/test/components/confirmation.js b/ui/test/components/confirmation.js index a563fb3..8eebb3e 100644 --- a/ui/test/components/confirmation.js +++ b/ui/test/components/confirmation.js @@ -1,32 +1,35 @@ import React from 'react'; import {shallow} from 'enzyme'; import chaiEnzyme from 'chai-enzyme' -import Confirmation from '../../app/components/confirmation'; +import sinon from 'sinon' import chai, { expect } from 'chai' +import Confirmation from '../../app/components/confirmation'; describe('Confirmation Component', () => { - const simpleFunction0 = () => {return 0} - const simpleFunction1 = () => {return 1} - it('Passed functionss run on click', () => { + const onAcceptFuncTest = sinon.spy(); + const onCancelFuncTest = sinon.spy(); + const confirmation = shallow( <Confirmation - onAccept={simpleFunction0} - onCancel={simpleFunction1} + onAccept={onAcceptFuncTest} + onCancel={onCancelFuncTest} /> ) - expect(confirmation.find('Button').get(0).props.onClick()).to.equal(simpleFunction0()) - expect(confirmation.find('Button').get(1).props.onClick()).to.equal(simpleFunction1()) + confirmation.find('Button').at(0).simulate('click') + expect(onAcceptFuncTest.calledOnce).to.equal(true) + confirmation.find('Button').at(1).simulate('click') + expect(onCancelFuncTest.calledOnce).to.equal(true) }) it('sets defaults correctly', () => { const confirmation = shallow( <Confirmation - onAccept={simpleFunction0} - onCancel={simpleFunction1} + onAccept={() => {}} + onCancel={() => {}} /> ) @@ -36,14 +39,16 @@ describe('Confirmation Component', () => { }) it('overwrites defaults correctly', () => { + const onAcceptFuncTest = () => {} + const onCancelFuncTest = () => {} const testTitle = "Test Title" const testAcceptStr = "Test accept string" const testCancelStr = "Test cancel string" const confirmation = shallow( <Confirmation - onAccept={simpleFunction0} - onCancel={simpleFunction1} + onAccept={() => {}} + onCancel={() => {}} title={testTitle} acceptStr={testAcceptStr} cancelStr={testCancelStr} |