0

I'm writing a unit test using jest. The function is a loadJsonData(). It takes in a string called URL at which the Json file can be found as well as whether or not to use user credentials. This is what my test looks like

it('should fetch JSON data successfully', async () => {
  const url = '../../data/mockData.json';
  const useCredentials = false;

  const result = await JsonLoader.loadJsonData(url, useCredentials);

  expect(result).toEqual({
    // expected data from mockData.json
    // ...
  });
});

I have my mockData.json file at the indicated relative directory, but I can't tell if it's working. How can I feed my function the actual relative directory to the mockData.json file instead of a standard html url?

Tiny Tim
  • 207
  • 1
  • 6
  • 1
    Does this answer your question? [Loading local JSON file](https://stackoverflow.com/questions/7346563/loading-local-json-file) – Eugene Jun 02 '23 at 05:18

0 Answers0