diff --git a/__tests__/SignaturePad.test.tsx b/__tests__/SignaturePad.test.tsx
index 69fbc3f..f3cc453 100644
--- a/__tests__/SignaturePad.test.tsx
+++ b/__tests__/SignaturePad.test.tsx
@@ -217,6 +217,9 @@ describe('Component', () => {
render();
const signaturePad = instance.current as SignaturePad;
+
+ signaturePad.fromDataURL(signature);
+
const spy = jest.spyOn(signaturePad.instance, 'toDataURL');
scaleCanvas(768, 768);
@@ -233,6 +236,9 @@ describe('Component', () => {
render();
const signaturePad = instance.current as SignaturePad;
+
+ signaturePad.fromDataURL(signature);
+
const spy = jest.spyOn(signaturePad.instance, 'toDataURL');
signaturePad.handleResize();
@@ -240,6 +246,20 @@ describe('Component', () => {
expect(spy).not.toHaveBeenCalled();
});
+ it('does not redraw a signature when the canvas is empty', () => {
+ const instance = React.createRef();
+
+ render();
+
+ const signaturePad = instance.current as SignaturePad;
+
+ expect(signaturePad.isEmpty()).toBeTruthy();
+
+ scaleCanvas(768, 768);
+
+ expect(signaturePad.isEmpty()).toBeTruthy();
+ });
+
it('does not add the resize event listener on mount', () => {
const spy = jest.spyOn(window, 'addEventListener');
const instance = React.createRef();
diff --git a/src/SignaturePad.tsx b/src/SignaturePad.tsx
index d3392e6..08eccc3 100644
--- a/src/SignaturePad.tsx
+++ b/src/SignaturePad.tsx
@@ -357,7 +357,7 @@ class SignaturePad extends React.PureComponent {
let data;
- if (this.props.redrawOnResize && this.signaturePad) {
+ if (this.props.redrawOnResize && this.signaturePad && !this.signaturePad.isEmpty()) {
data = this.signaturePad.toDataURL();
}