mercredi 26 octobre 2016

Error in testing Promise with Mocha - 'TypeError: Cannot read property 'resolve' of undefined'

I keep getting the error 'TypeError: Cannot read property 'resolve' of undefined,' and I don't know why it's happening. Any thoughts?

describe('render fn', () => {
    it('should return a string', () => {
        let filename = __filename, 
            content = 'Hello, World', 
            theme = './test.less';
        return file.render(filename, content, theme)
            .then((css) => {
                expect(css).to.be.a('string');
        });
    });
});

Here's the code I'm trying to test:

render(filename, content, theme) {
    return new Promise((resolve, reject) => {
        let options = JSON.parse(JSON.stringify(this.config.renderOptions));

        if (theme)
            options.paths.push(path.resolve(this.config.theme.path, theme));

        options.paths.push(path.resolve(this.config[filename].resolve.root));

        less.render(content, options, (e, output) => {
            if (e != null) reject(e);
            resolve(output.css);
        });
    });
}

I've been working on this for a long time now, and I'd appreciate any help. Thanks!

Aucun commentaire:

Enregistrer un commentaire