打字稿摩卡
我无法在摩卡咖啡测试中使用svg.js。
这是我在ts项目中使用的命令。如何在Mocha中使用svg.js? 只要看下面的代码,它表明我不能在mocha测试文件中使用svg.js。但是我可以在其他文件中使用svg.js。如何导入三部分模块?
mocha --require ts-node/register -r jsdom-global/register -r svg.js src/Test/**/*.ts
import {expect} from "chai";
import * as SVG from "svg.js";
import {Line} from "../../Annotator/Entities/Line";
import {Word} from "../../Annotator/Entities/Word";
before(function () {
this.jsdom = require('jsdom-global')();
})
after(function () {
this.jsdom();
})
describe("Line", () => {
it("append", () => {
// const SVG = require('svg.js');
var parent = document.createElement("div");
parent.id = 'drawing';
var drawing = document.getElementById('drawing');
let svgDoc = SVG(drawing).size(100, 100);
let word1 = new Word(svgDoc, 100, 100, 16, "1");
let word2 = new Word(svgDoc, 105, 100, 16, "2");
let word3 = new Word(svgDoc, 110, 100, 16, "3");
let line = new Line(svgDoc, 0, 0, 16);
line.append(word1).append(word2).append(word3);
expect(word1.prevContent).equals(null);
expect(word1.nextContent).equals(word2);
expect(word2.prevContent).equals(word1);
expect(word2.nextContent).equals(word3);
expect(word3.prevContent).equals(word2);
expect(word3.nextContent).equals(null);
});
});
Line
1) append
0 passing (29ms)
1 failing
1) Line
append:
TypeError: SVG is not a function
at Context.<anonymous> (src/Test/UnitTest/Line.ts:23:22)
如何在摩卡咖啡中使用svg.js?