|
1 |
| -import { describe, it, test, expect } from 'jest' |
| 1 | +import jest, { describe, it, test, expect } from 'jest' |
2 | 2 | import { mount } from 'enzyme'
|
3 | 3 | import React from 'react'
|
4 | 4 |
|
@@ -191,3 +191,33 @@ describe('canvas resizing', () => {
|
191 | 191 | expect(canvas.height).toBe(size.height)
|
192 | 192 | })
|
193 | 193 | })
|
| 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