柴如承诺即使错了也会过去
Chai-As-Promised passes even when it is wrong
const chaiAsPromised = require('chai-as-promised');
const chai = require('chai');
const expect = chai.expect;
chai.use(chaiAsPromised);
describe('[sample unit]', function() {
it('should pass functionToTest with true input', function() {
expect(Promise.resolve({ foo: "bar" })).to.eventually.have.property("meh");
});
});
此测试通过???我正在使用"chai":"3.5.0","chai-as-promised":"5.2.0",
expect(...)
返回一个承诺本身,该承诺将被解析或拒绝,具体取决于测试。
该承诺的结果,您需要从测试用例中显式返回它(这有效是因为 Mocha 具有内置的承诺支持(:
describe('[sample unit]', function() {
it('should pass functionToTest with true input', function() {
return expect(Promise.resolve({ foo: "bar" })).to.eventually.have.property("meh");
});
});
或者,您可以使用 Mocha 的"常规"回调式异步设置和 chai-as-promise 的.notify()
:
describe('[sample unit]', function() {
it('should pass functionToTest with true input', function(done) {
expect(Promise.resolve({ foo: "bar" })).to.eventually.have.property("meh").notify(done);
});
});
相关文章:
- reducers在redux中得到Function not Object,what'it’他错了
- 正在尝试为Docpad网站设置Lunr全文搜索插件.我做错了什么
- 谷歌关闭注释赢得'Don’不要告诉我;I’我错了
- Javascript对象/原型.我的理解错了吗
- 什么'这个随机数猜谜游戏错了
- 重新加载重复数据失败,我做错了什么
- 什么'这个谷歌脚本错了
- 柴如承诺即使错了也会过去
- 什么'Gulp错了
- 我做错了什么
- angular mongodb数组格式写错了
- JavaScript排序算法不起作用 - 任何明显的我做错了
- Google Apps 脚本为 getLastRow 抛出电子邮件失败通知,我做错了什么
- Javascript语法 - 我做错了什么
- 角度灯箱不起作用.我做错了什么
- 在这个猫鼬独特的保存前验证中,我做错了什么
- fullcalendar赢得't让我调整事件大小(光标不显示,我做错了)
- document.getElementById为空..什么'I’我的代码错了.
- 分析错误失败-What'It’他错了
- 简单的Youtube iframe API就在文档中,我做错了什么