How to load external Json file using karma+Jasmine for angularJS testing?/

前端 未结 3 966
终归单人心
终归单人心 2020-12-17 22:38

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 b

3条回答
  •  [愿得一人]
    2020-12-17 23:43

    Set the path to find your file, in this case my file (staticData.json) is located under /test folder.

    jasmine.getFixtures().fixturesPath = 'base/test/';
    staticData= JSON.parse(jasmine.getFixtures().read("staticData.json"));
    

    You have to add also the pattern in the karma.conf.js file, something like:

     { pattern: 'test/**/*.json', included: false, served: true}
    

提交回复
热议问题