Search code examples
unit-testingmocha.jsrelative-pathjsdom

How to load html file in jsdom with relative path?


This is not working eventhough relative path given here is correct

before(function(done) {
    JSDOM.fromFile('../../../src/main/resources/templates/components/xyz.html')
            .then((dom) => {
                global.document = dom.window.document;
            })
            .then(done, done);
        });

instead loading directly with absolute path is working fine

before(function(done) {
        JSDOM.fromFile('v:/folder_main/src/main/resources/templates/components/xyz.html')
                .then((dom) => {
                    global.document = dom.window.document;
                })
                .then(done, done);
            });

what to do for loading jsdom.fromfile with relative path


Solution

  • Providing the path as below solved the issue for me

        JSDOM.fromFile('src/main/resources/templates/components/xyz.html')