|
1 | 1 | import { jest, describe, it, test, expect } from '@jest/globals'
|
2 |
| -import { render } from '@testing-library/react'; |
| 2 | +import { render, RenderResult } from '@testing-library/react' |
3 | 3 | import React from 'react'
|
4 | 4 |
|
5 | 5 | import { SignatureCanvas, SignatureCanvasProps } from '../src/index'
|
6 | 6 | import { propsF, dotF } from './fixtures'
|
7 | 7 |
|
8 |
| -function renderSCWithRef (props?: SignatureCanvasProps) { |
| 8 | +function renderSCWithRef (props?: SignatureCanvasProps): { wrapper: RenderResult, instance: SignatureCanvas, ref: React.RefObject<SignatureCanvas> } { |
9 | 9 | const ref = React.createRef<SignatureCanvas>()
|
10 | 10 | const wrapper = render(<SignatureCanvas {...props} ref={ref} />)
|
11 |
| - const instance = ref.current! |
| 11 | + const instance = ref.current! // eslint-disable-line @typescript-eslint/no-non-null-assertion -- this simplifies the code; it does exist immediately after render. it won't exist after unmount, but we literally test for that separately |
12 | 12 | return { wrapper, instance, ref }
|
13 | 13 | }
|
14 | 14 |
|
@@ -124,7 +124,7 @@ describe('SigCanvas wrapper methods return equivalent to SigPad', () => {
|
124 | 124 |
|
125 | 125 | // comes after props and wrapper methods as it uses both
|
126 | 126 | describe('get methods', () => {
|
127 |
| - const { instance } = renderSCWithRef({canvasProps: dotF.canvasProps}) |
| 127 | + const { instance } = renderSCWithRef({ canvasProps: dotF.canvasProps }) |
128 | 128 | instance.fromData(dotF.data)
|
129 | 129 |
|
130 | 130 | test('getCanvas should return the same underlying canvas', () => {
|
@@ -165,7 +165,7 @@ describe('canvas resizing', () => {
|
165 | 165 | const size = { width: 100, height: 100 }
|
166 | 166 | it('should not change size if fixed width & height', () => {
|
167 | 167 | // reset clearOnResize back to true after previous test
|
168 |
| - wrapper.rerender(<SignatureCanvas ref={ref} clearOnResize={true} canvasProps={size} />) |
| 168 | + wrapper.rerender(<SignatureCanvas ref={ref} clearOnResize canvasProps={size} />) |
169 | 169 | window.resizeTo(500, 500)
|
170 | 170 |
|
171 | 171 | expect(canvas.width).toBe(size.width)
|
|
0 commit comments