0

I am trying to load json from local folder and then feed it into function to test it. Here is what I am trying to do:

it('should be able to use treatExpResultJSON() function to treat incoming JSON', function() {
   require(['./jsonSampleData.json'], function(json){
      expect(dirService.treatExpResultJSON(json)).not.toBeNull();
      expect(dirService.treatExpResultJSON(json)).not.toBeUndefined();
      console.log(json);
      console.log("Testing json passed!");
   });   

});

expect is not working inside the require callback function, I guess, it is not called at all since with both .not.toBeNull(), not.toBeUndefined() and .toBeNull(), toBeUndefined() the test is showing success. Also, console.log() are not working inside the function. So, how should I actually load the json, then supply it to the function?

Nikita Vlasenko
  • 4,004
  • 7
  • 47
  • 87

1 Answers1

1

Try this:

json = require('./jsonSampleData.json');

it('should be able to use treatExpResultJSON() function to treat incoming JSON', function() {
  expect(dirService.treatExpResultJSON(json)).not.toBeNull();
  expect(dirService.treatExpResultJSON(json)).not.toBeUndefined();
  console.log(json);
  console.log("Testing json passed!");
});

I use this structure in my tests, and works.

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49