Last active
July 26, 2017 14:30
-
-
Save TheDutchCoder/7260fd66be953046dc1542fd2ba5bf94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// other tests | |
it('should toggle the component when it\'s open and ESC is pressed', (done) => { | |
vm = createTest(CpColorPicker, defaultProps) | |
expect(vm.isOpen).to.equal(false) | |
vm.isOpen = true | |
Vue.nextTick(() => { | |
expect(vm.isOpen).to.equal(true) | |
// I can't create multiple mocked events here to test the `let key = 'which' in e ? e.which : e.keyCode` case. | |
// This needs a separate test where I'm just repeating things over and over. | |
// `if (key === 27 && this.isOpen)` also needs additional tests, so I end up with 4 tests I just want to wrap in one, because they all test the same behaviour. | |
let event = { keyCode: 27 } | |
sinon.spy(vm, 'handleKeyUp') | |
sinon.spy(vm, 'toggle') | |
vm.handleKeyUp(event) | |
expect(vm.handleKeyUp.callCount).to.equal(1) | |
expect(vm.toggle.callCount).to.equal(1) | |
vm.handleKeyUp.restore() | |
vm.toggle.restore() | |
done() | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
methods: { | |
handleKeyUp (e) { | |
let key = 'which' in e ? e.which : e.keyCode // This branch needs 2 tests | |
if (key === 27 && this.isOpen) { // This branch needs 2 additional tests | |
this.toggle() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment