【发布时间】:2015-11-27 17:18:29
【问题描述】:
我在我的 karma.conf.js 文件数组中包含了一个现有的项目文件:
files : [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/js/**/*.js',
'test/unit/**/*.js',
'bower.json',
'app/data/file.json',
],
我知道文件已匹配,因为我没有收到警告
WARN [watcher]: Pattern <pattern> does not match any file.我将该行更改为一个已知的不存在的文件并返回到仔细检查。
我的基本路径是项目根目录:
basePath : '../',
当 Angular 的 controllersSpec.js 运行时,我使用 XHR GET 同步加载文件,但我得到一个 HTTP 404。文件在哪里?
//Synchronously GET the test data
var req = new XMLHttpRequest();
req.open('GET', 'app/data/file.json', false);
req.send(null);
var testData = JSON.parse(req.responseText);
然后,在测试shell中,我看到了:
WARN [web-server]: 404: /app/data/file.json
<user agent> ERROR
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
at <path to project>/test/unit/controllersSpec.js:12
【问题讨论】:
标签: angularjs node.js karma-runner karma-jasmine