Skip to content

Commit

Permalink
test: add test case for constructor options with explicit undefined
Browse files Browse the repository at this point in the history
… values
  • Loading branch information
cyevgeniy committed May 18, 2024
1 parent 782bc3e commit 302eac6
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/signature_pad.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SignaturePad from '../src/signature_pad';
import type { Options } from '../src/signature_pad';
import { face } from './fixtures/face';
import { square } from './fixtures/square';
import './utils/pointer-event-polyfill';
Expand Down Expand Up @@ -37,6 +38,51 @@ describe('#constructor', () => {

expect(pad.minDistance).toBe(0);
});

it("uses fallback values for options with explicit 'undefined'", () => {
const opts: Options = {
dotSize: undefined,
minWidth: undefined,
maxWidth: undefined,
penColor: undefined,
velocityFilterWeight: undefined,
compositeOperation: undefined,
minDistance: undefined,
backgroundColor: undefined,
throttle: undefined,
canvasContextOptions: undefined,
};

const exp: Options = {
dotSize: 0,
minWidth: 0.5,
maxWidth: 2.5,
penColor: 'black',
velocityFilterWeight: 0.7,
compositeOperation: 'source-over',
minDistance: 5,
backgroundColor: 'rgba(0,0,0,0)',
throttle: 16,
canvasContextOptions: {},
};

const pad = new SignaturePad(canvas, opts);

const actual = {
dotSize: pad.dotSize,
minWidth: pad.minWidth,
maxWidth: pad.maxWidth,
penColor: pad.penColor,
velocityFilterWeight: pad.velocityFilterWeight,
compositeOperation: pad.compositeOperation,
minDistance: pad.minDistance,
backgroundColor: pad.backgroundColor,
throttle: pad.throttle,
canvasContextOptions: pad.canvasContextOptions,
};

expect(actual).toStrictEqual(exp);
});
});

describe('#clear', () => {
Expand Down

0 comments on commit 302eac6

Please sign in to comment.