[英]How to Assert a Failure With backstopjs in a mocha framework using Chai
I'm trying to create a visual regression framework using mocha, with the visual diff done using backstopjs. 我正在尝试使用mocha创建视觉回归框架,并使用backstopjs完成视觉差异。
I've got a small first test running, but when I intentionally fail the test, I'd like the mocha framework to acknowledge the failure and report this. 我有一个小的第一次测试运行,但是当我故意未通过测试时,我希望mocha框架能够确认失败并报告此情况。 As It stands, when running the mocha framework everything goes as I'd expect, but the mocha report still shows as a pass, even though backstopjs is reporting the failure.
正如它所代表的那样,当运行mocha框架时,一切都按照我的预期进行,但是即使backstopjs报告失败,mocha报告仍然显示为通过。
Here is my sample test 这是我的样品测试
const assert = require('chai').assert
const backstop = require('backstopjs')
describe('Navigation To Google', () => {
it('and take a screenshot', () => {
backstop('test', {config: './backstop.json'})
.then(() => {
console.log('backstop test')
}).catch((e) => {
//If fails catch error here
console.log(`The error is ${e}`)
})
// I assume I need to handle the assertion here
});
})
My github and the code can be viewed here: https://github.com/Kpizzle/PupperDif 我的github和代码可以在这里查看: https : //github.com/Kpizzle/PupperDif
Solve my question, I'm pretty new to Javascript and still have to wrap my head around the async nature of it. 解决我的问题,我对Javascript很新,但仍然要围绕它的异步性质。
I added an async await to the code. 我在代码中添加了一个异步等待。 See new code.
查看新代码。
const assert = require("chai").assert;
const backstop = require("backstopjs");
describe("Navigation To Google", () => {
it("and take a screenshot", async () => {
await backstop("test", { config: "./backstopScenarios/backstop.google.json" })
.then(() => {
console.log("backstop test");
})
.catch(e => {
//If fails catch error here
assert.ifError(e);
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.