我想爲我的打字稿類從JSON文件中讀取數據創建一個測試..如何從因緣訪問JSON文件測試
readData<T>(filePath: string): Promise<T> {
return Qajax.getJSON(filePath);
}
我用的茉莉和因果報應的環境進行測試。我的問題是,即使我添加了因果報應內的任何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文件不存在的測試總是失敗..
主要的問題在這裏是JSON文件沒有因果報應環境得到加載。當您從Chrome啓動器檢查源文件時,您看不到文件「/base/tests/framework/common/app_config.json」..所有其他.js文件都可見。 –