【发布时间】:2016-02-29 12:15:49
【问题描述】:
我正在尝试为我的 typescript 类创建一个测试,该类从 json 文件中读取数据..
readData<T>(filePath: string): Promise<T> {
return Qajax.getJSON(filePath);
}
我正在使用 Jasmine 和 karma 环境进行测试。我的问题是,即使我在 karma 中添加任何 json 文件,它也不会加载到 chrome 启动器中
files: [
'libs/angular/angular.js',
'libs/angular/angular-route.js',
'libs/angular/angular-mocks.js',
'libs/collections/collections.js',
'tests/framework/common/app_config.json',
'tests/package.json',
{ pattern: 'libs/qajax/qajax.js', included: false },
{ pattern: 'libs/q/q.js', included: false },
{ pattern: 'tests/framework/**/*.js', included: false },
{ pattern: 'tests/toolpattern/**/*.js', included: false },
{ pattern: 'tests/test-main.js', included: true },
]
正如您在上面的业力配置中看到的,我添加了一个名为 app_config.json 的文件。现在我正在尝试从测试中读取该文件...
it("read data test.", function (done) {
var promise = configurationAccessorImpl.readData("tests/framework/common/app_config.json");
promise.then(result => {
console.info("Get configuration test - Success.");
}, error => {
console.log(error);
});
});
测试总是失败,因为 json 文件不存在..
【问题讨论】:
-
This question 有更好的答案
标签: json typescript jasmine karma-runner