vendredi 24 août 2018

Angular2+ - Cannot find module when passed as variable - testing

In my test I am requiring a .json file with data that I will check against. However, I cannot seem to pass the string of where to find it into the require...

Working code

const data = require('../../../assets/data.json');

Does not work

const jsonUrl = '../../../assets/data.json';
const data = require(jsonUrl);

I am wanting to use the variable jsonUrl as this url string is to be used a few times within the test itself. I just don't understand why it cannot find it?

Aucun commentaire:

Enregistrer un commentaire