我正在尝试让用 TypeScript 编写的 Mocha 单元测试在Node Tools for Visual Studio的 Visual Studio 2015 Community Edition 中工作。我收到此错误(在“输出”窗口的Tests
部分中):
------ Discover test started ------
Processing: <lot of *.js** files>...
Test discovery error: [TypeError: Cannot read property 'replace' of undefined] in C:\Code\ov\BuyCo\test\sellers\testPersistance.js
Test discovery error: [TypeError: Cannot read property 'replace' of undefined] in C:\Code\ov\BuyCo\test\sellers\testUserPersistance.js
...<andsoon>
Processing finished for framework of Mocha
Discovered 0 testcases.
========== Discover test finished: 0 found (0:00:01.4378126) ==========
所以它列出了 .js 文件而不是 ts,那些已经被编译出来了,但是在这些函数中生成的代码中绝对没有replace
函数。所以这是一个非常奇怪的错误。我正在使用 Typescript 1.7。
npm test ...
从命令提示符 ( )运行时,测试正在运行。但我希望能够设置(注意我正在测试 NodeJS 代码,例如服务器端 CommonJS)。
注意:在分析过程中,我已经将一个测试文件简化为默认的打字稿示例文件,但它会引发相同的错误,所以这不应该是问题:
import assert = require('assert');
describe("Test Suite 1", () => {
it("Test A", () => {
assert.ok(true, "This shouldn't fail");
});
it("Test B", () => {
assert.ok(1 === 1, "This shouldn't fail");
assert.ok(false, "This should fail ts");
});
});