diff --git a/package.json b/package.json index f0529d841c03a01e7287bb7a34d64dbecb7e0080..0b60b0e5cdd466edfb045f0e11a9455dc11d62fd 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ }, "dependencies": { "consola": "2.15.3", + "jest-canvas-mock": "^2.5.0", "sass": "^1.50.0", "vscode": "^1.1.37", "vue-router": "^4.0.12" diff --git a/src/packages/__VUE/signature/__tests__/signature.spec.ts b/src/packages/__VUE/signature/__tests__/signature.spec.ts index d25e487922bd9a65d23a3921597c9b4e5b13b6ff..3fd64ba64b56a4131026a73a861c76dc5e2664fc 100644 --- a/src/packages/__VUE/signature/__tests__/signature.spec.ts +++ b/src/packages/__VUE/signature/__tests__/signature.spec.ts @@ -3,7 +3,7 @@ import Signature from '../index.vue'; import NutIcon from '../../icon/index.vue'; import NutButton from '../../button/index.vue'; import { nextTick, reactive, toRefs } from 'vue'; -import { createCanvas } from 'canvas'; +import 'jest-canvas-mock'; function sleep(delay = 0): Promise { return new Promise((resolve) => { @@ -42,16 +42,18 @@ test('props custom-class', async () => { const signatureWrapper = wrapper.findAll('.nut-signature'); expect(signatureWrapper[0].classes()).toContain(wrapper.vm.customClass); - const canvas = createCanvas(200, 200); + const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); - ctx.lineWidth = wrapper.vm.lineWidth; - ctx.strokeStyle = wrapper.vm.strokeStyle; - ctx.beginPath(); - ctx.lineTo(10, 50); - ctx.lineTo(80, 120); - ctx.stroke(); - const _img = document.createElement('img'); - _img.src = canvas.toDataURL(); - expect(canvas.toDataURL()).not.toBeNull(); - // expect(wrapper.html()).toMatchSnapshot(); + if (ctx) { + ctx.lineWidth = wrapper.vm.lineWidth; + ctx.strokeStyle = wrapper.vm.strokeStyle; + ctx.beginPath(); + ctx.lineTo(10, 50); + ctx.lineTo(80, 120); + ctx.stroke(); + const _img = document.createElement('img'); + _img.src = canvas.toDataURL(); + expect(canvas.toDataURL()).not.toBeNull(); + // expect(wrapper.html()).toMatchSnapshot(); + } });