使用Mocha测试Promise时出错'TypeError: Cannot read property '
Error in testing Promise with Mocha - 'TypeError: Cannot read property 'resolve' of undefined'
我一直得到错误'TypeError:无法读取属性'resolve'的未定义',我不知道为什么会发生。任何想法吗?
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');
});
});
});
下面是我要测试的代码:
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);
});
});
}
我已经研究这个很长时间了,我很感激任何帮助。谢谢!
我一直得到错误'TypeError:不能读取属性'resolve'的我不知道为什么会这样。任何想法吗?
问题出在这一行:
options.paths.push(path.resolve(this.config[filename].resolve.root));
,试图读取对象this.config[filename]
上的属性.resolve
。错误信息告诉您对象是undefined
。你的代码等于:
var myObject = undefined;
console.log(myObject.resolve); //Cannot read property 'resolve' of undefined
我不能从你在你的问题中列出的代码告诉为什么this.config[filename]
是undefined
。
相关文章:
- 未捕获TypeError: Cannot read property 'geocode'未定义的'
- SailsJs中的错误.TypeError: Cannot read property '的定义
- 未捕获的TypeError: Cannot read property 'top'的定义
- 未捕获的TypeError: Cannot read property '未定义的数据表
- 未捕获的TypeError: Cannot read property 'timing'的定义
- 未捕获的TypeError: Cannot read property 'checked'零
- 未捕获的TypeError: Cannot read property 'top'在引导中单击导航栏时未
- “未捕获的TypeError: Cannot read”属性是什么?JS误差均值
- Extjs5 treepanel [Uncaught TypeError: Cannot read property &
- TypeError: Cannot read property 'submit'添加到购物车'
- Rails和React: TypeError: Cannot call method 'map'的定义
- 添加自定义jquery.验证方法导致Uncaught TypeError: Cannot read property &
- Userscript在Firefox中工作,但Chrome给出:Uncaught TypeError: Cannot r
- node.js中的回调函数.TypeError: Cannot call method 'emit'的定
- asp:textbox Uncaught TypeError: Cannot read property 'va
- TypeError: Cannot read property 'search' of undefine
- 未捕获的TypeError: Cannot read property 'current'在选择任何选项
- 未捕获的TypeError: Cannot read property '3'的定义
- jquery-ui.js:12443未捕获的TypeError: Cannot read property 'a
- jquery Uncaught TypeError: Cannot read property 'left