I am currently working on developing a test for my TypeScript class that involves retrieving data from a JSON file.
readData<T>(filePath: string): Promise<T> {
return Qajax.getJSON(filePath);
}
For testing purposes, I am utilizing the Jasmine and Karma environment. However, I have encountered an issue where despite adding JSON files to Karma, they are not being loaded in the Chrome launcher.
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 },
]
In the above Karma configuration, you can see that I have included a file named app_config.json. Nevertheless, I am facing difficulties reading this file during testing...
it("test to read data.", 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);
});
});
The test consistently fails due to the unavailability of the JSON file...