我有一个文件src / core / version.ts
module MyModule.Core {
/** Version information. */
export class Version {
/** The informal version. */
public static getInformalVersion(): string {
return "1.0 Beta 1";
}
}
}
export default MyModule.Core.Version;
和test test / core / version.test.ts
import {assert} from 'chai';
import Version from "../../src/core/version";
describe('Version',()=>{
it('getInformalVersionTest',()=> {
let number =Version.getInformalVersion();
assert.isNotNull(number);
});
});
如果我运行mocha test --recursive
error TS1148: Cannot compile modules unless the '--module' flag is provided.
此字符串中的错误
export default MyModule.Core.Version;
如果我清除它grunt编译项目但是mocha测试失败
TS23006 File './src/core/version.ts' is not a module
请告诉我如何将类版本导入测试版本.test.ts
答案 0 :(得分:-1)
我找到了解决方案:
import {assert} from 'chai';
import * as fs from "fs";
var fileContent = fs.readFileSync("./src/core/version.js", "utf8");
if( fileContent.indexOf("exports.MyModule = MyModule;") === -1 )
fs.appendFileSync('./src/core/version.js', "\n exports.MyModule = MyModule;");
import * as MyModule from "../../src/core/version.js";
import Version = MyModule.MyModule.Core.Version;
describe('Version',()=>{
it('getInformalVersionTest',()=> {
let number =Version.getInformalVersion();
assert.isNotNull(number);
});
});