提交 9c9c7756 编写于 作者: m0_68080989's avatar m0_68080989

chore: canvas -> jest-canvas-mock

上级 416354a3
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
}, },
"dependencies": { "dependencies": {
"consola": "2.15.3", "consola": "2.15.3",
"jest-canvas-mock": "^2.5.0",
"sass": "^1.50.0", "sass": "^1.50.0",
"vscode": "^1.1.37", "vscode": "^1.1.37",
"vue-router": "^4.0.12" "vue-router": "^4.0.12"
......
...@@ -3,7 +3,7 @@ import Signature from '../index.vue'; ...@@ -3,7 +3,7 @@ import Signature from '../index.vue';
import NutIcon from '../../icon/index.vue'; import NutIcon from '../../icon/index.vue';
import NutButton from '../../button/index.vue'; import NutButton from '../../button/index.vue';
import { nextTick, reactive, toRefs } from 'vue'; import { nextTick, reactive, toRefs } from 'vue';
import { createCanvas } from 'canvas'; import 'jest-canvas-mock';
function sleep(delay = 0): Promise<void> { function sleep(delay = 0): Promise<void> {
return new Promise((resolve) => { return new Promise((resolve) => {
...@@ -42,16 +42,18 @@ test('props custom-class', async () => { ...@@ -42,16 +42,18 @@ test('props custom-class', async () => {
const signatureWrapper = wrapper.findAll('.nut-signature'); const signatureWrapper = wrapper.findAll('.nut-signature');
expect(signatureWrapper[0].classes()).toContain(wrapper.vm.customClass); expect(signatureWrapper[0].classes()).toContain(wrapper.vm.customClass);
const canvas = createCanvas(200, 200); const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
ctx.lineWidth = wrapper.vm.lineWidth; if (ctx) {
ctx.strokeStyle = wrapper.vm.strokeStyle; ctx.lineWidth = wrapper.vm.lineWidth;
ctx.beginPath(); ctx.strokeStyle = wrapper.vm.strokeStyle;
ctx.lineTo(10, 50); ctx.beginPath();
ctx.lineTo(80, 120); ctx.lineTo(10, 50);
ctx.stroke(); ctx.lineTo(80, 120);
const _img = document.createElement('img'); ctx.stroke();
_img.src = canvas.toDataURL(); const _img = document.createElement('img');
expect(canvas.toDataURL()).not.toBeNull(); _img.src = canvas.toDataURL();
// expect(wrapper.html()).toMatchSnapshot(); expect(canvas.toDataURL()).not.toBeNull();
// expect(wrapper.html()).toMatchSnapshot();
}
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册