如何利用人缘+茉莉angularJS测试加载外部JSON文件?/ [英] How to load external Json file using karma+Jasmine for angularJS testing?/
问题描述
谁能给我一个例子,PLUNKER该如何加载JSON文件人缘/茉莉test.I欲读取JSON文件中的数据的测试案例我是笔迹。一直在寻找,但无处他们提到明显的例子如何做到这一点?我AP preciate它,如果任何人都可以使用的示例提供。
Can anyone provide me an example in PLUNKER that how to load JSON file for karma/jasmine test.I want to read the data from JSON file for the test cases i am writing.I have been searching but nowhere they mentioned clear example on how to do it? I appreciate it if anyone can provide with the example.
推荐答案
你想读一个网络服务器或本地文件系统中的JSON文件?没有人能够从Plunker本地文件系统给负载的一个例子,因为它在Web浏览器上运行,被拒绝访问到文件系统。
Do you want to read the JSON file from a webserver or a local file system? No one can give an example of loading from a local file system from Plunker, since it runs in a web browser and is denied access to the file system.
下面是如何从磁盘加载一个JSON文件中的任何程序的Node.js为例,应噶/茉莉花工作:
Here is an example of how to load a JSON file from disk in any Node.js program, this should work for Karma/Jasmine:
var fs = require('fs');
var filename = './test.json';
fs.readFile(filename, 'utf8', function (err, data) {
if (err) {
console.log('Error: ' + err);
return;
}
data = JSON.parse(data);
console.dir(data);
});
这篇关于如何利用人缘+茉莉angularJS测试加载外部JSON文件?/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!