Skip to content

Commit 3bd83ac

Browse files
committed
(test): ensure on & off methods work properly
- 100% statement coverage now woooooot!
1 parent 8943693 commit 3bd83ac

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/index.spec.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, test, expect } from 'jest'
1+
import jest, { describe, it, test, expect } from 'jest'
22
import { mount } from 'enzyme'
33
import React from 'react'
44

@@ -191,3 +191,33 @@ describe('canvas resizing', () => {
191191
expect(canvas.height).toBe(size.height)
192192
})
193193
})
194+
195+
// comes after wrappers and resizing as it uses both
196+
describe('on & off methods', () => {
197+
const wrapper = mount(<SignatureCanvas />)
198+
const instance = wrapper.instance()
199+
200+
it('should not clear when off, should clear when back on', () => {
201+
instance.fromData(dotF.data)
202+
expect(instance.isEmpty()).toBe(false)
203+
204+
instance.off()
205+
window.resizeTo(500, 500)
206+
expect(instance.isEmpty()).toBe(false)
207+
208+
instance.on()
209+
window.resizeTo(500, 500)
210+
expect(instance.isEmpty()).toBe(true)
211+
})
212+
213+
it('should no longer fire after unmount', () => {
214+
// monkey-patch on with a mock to tell if it were called, as there's no way
215+
// to check what event listeners are attached to window
216+
instance._on = instance.on
217+
instance.on = jest.fn(instance._on)
218+
219+
wrapper.unmount()
220+
window.resizeTo(500, 500)
221+
expect(instance.on).not.toBeCalled()
222+
})
223+
})

0 commit comments

Comments
 (0)