如何使用 karma+Jasmine 加载外部 Json 文件进行 angularJS 测试?/ [英] How to load external Json file using karma+Jasmine for angularJS testing?/

查看:28
本文介绍了如何使用 karma+Jasmine 加载外部 Json 文件进行 angularJS 测试?/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能在 PLUNKER 中为我提供一个示例,说明如何为 karma/jasmine 测试加载 JSON 文件.我想从 JSON 文件中读取我正在编写的测试用例的数据.我一直在搜索,但他们没有提到明确的示例怎么办呢?如果有人可以提供示例,我将不胜感激.

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.

推荐答案

您可以使用 require 加载外部 json 数据文件

You can load an external json data file using require

var data = require('./data.json');
console.log(data);
// Your test cases goes here and you can use data object

这篇关于如何使用 karma+Jasmine 加载外部 Json 文件进行 angularJS 测试?/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆