11import { jest , describe , it , test , expect } from 'jest-without-globals'
2- import { mount } from 'enzyme'
2+ import { mount , CommonWrapper } from 'enzyme'
33import React from 'react'
44
5- import SignatureCanvas from '../src/index.tsx'
6- import { propsF , dotF } from './fixtures.js'
5+ import SignatureCanvas from '../src/index'
6+ import { propsF , dotF } from './fixtures'
7+
8+ function rSCInstance ( wrapper : CommonWrapper ) : SignatureCanvas {
9+ return wrapper . instance ( ) as SignatureCanvas
10+ }
711
812test ( 'mounts canvas and instance properly' , ( ) => {
913 const wrapper = mount ( < SignatureCanvas /> )
1014 expect ( wrapper . exists ( 'canvas' ) ) . toBe ( true )
11- const instance = wrapper . instance ( )
15+ const instance = rSCInstance ( wrapper )
1216 expect ( instance . isEmpty ( ) ) . toBe ( true )
1317} )
1418
1519describe ( 'setting and updating props' , ( ) => {
1620 it ( 'should set default props' , ( ) => {
17- const instance = mount ( < SignatureCanvas /> ) . instance ( )
21+ const instance = rSCInstance ( mount ( < SignatureCanvas /> ) )
1822 expect ( instance . props ) . toStrictEqual ( SignatureCanvas . defaultProps )
1923 } )
2024
2125 it ( 'should set initial mount props and SigPad options' , ( ) => {
22- const instance = mount ( < SignatureCanvas { ...propsF . all } /> ) . instance ( )
26+ const instance = rSCInstance ( mount ( < SignatureCanvas { ...propsF . all } /> ) )
2327 const sigPad = instance . getSignaturePad ( )
2428
2529 expect ( instance . props ) . toMatchObject ( propsF . all )
@@ -28,7 +32,7 @@ describe('setting and updating props', () => {
2832
2933 it ( 'should update props and SigPad options' , ( ) => {
3034 const wrapper = mount ( < SignatureCanvas /> )
31- const instance = wrapper . instance ( )
35+ const instance = rSCInstance ( wrapper )
3236 const sigPad = instance . getSignaturePad ( )
3337
3438 // default props and options should not match new ones
@@ -43,7 +47,7 @@ describe('setting and updating props', () => {
4347} )
4448
4549describe ( 'SigCanvas wrapper methods return equivalent to SigPad' , ( ) => {
46- const rSigPad = mount ( < SignatureCanvas /> ) . instance ( )
50+ const rSigPad = rSCInstance ( mount ( < SignatureCanvas /> ) )
4751 const sigPad = rSigPad . getSignaturePad ( )
4852
4953 test ( 'toData should be equivalent' , ( ) => {
@@ -118,9 +122,9 @@ describe('SigCanvas wrapper methods return equivalent to SigPad', () => {
118122
119123// comes after props and wrapper methods as it uses both
120124describe ( 'get methods' , ( ) => {
121- const instance = mount (
125+ const instance = rSCInstance ( mount (
122126 < SignatureCanvas canvasProps = { dotF . canvasProps } />
123- ) . instance ( )
127+ ) )
124128 instance . fromData ( dotF . data )
125129
126130 test ( 'getCanvas should return the same underlying canvas' , ( ) => {
@@ -138,7 +142,7 @@ describe('get methods', () => {
138142// comes after props, wrappers, and gets as it uses them all
139143describe ( 'canvas resizing' , ( ) => {
140144 const wrapper = mount ( < SignatureCanvas /> )
141- const instance = wrapper . instance ( )
145+ const instance = rSCInstance ( wrapper )
142146 const canvas = instance . getCanvas ( )
143147
144148 it ( 'should clear on resize' , ( ) => {
@@ -196,7 +200,7 @@ describe('canvas resizing', () => {
196200// comes after wrappers and resizing as it uses both
197201describe ( 'on & off methods' , ( ) => {
198202 const wrapper = mount ( < SignatureCanvas /> )
199- const instance = wrapper . instance ( )
203+ const instance = rSCInstance ( wrapper )
200204
201205 it ( 'should not clear when off, should clear when back on' , ( ) => {
202206 instance . fromData ( dotF . data )
@@ -214,8 +218,8 @@ describe('on & off methods', () => {
214218 it ( 'should no longer fire after unmount' , ( ) => {
215219 // monkey-patch on with a mock to tell if it were called, as there's no way
216220 // to check what event listeners are attached to window
217- instance . _on = instance . on
218- instance . on = jest . fn ( instance . _on )
221+ const origOn = instance . on
222+ instance . on = jest . fn ( origOn )
219223
220224 wrapper . unmount ( )
221225 window . resizeTo ( 500 , 500 )
0 commit comments