简体   繁体   English

如何使用Chai在Mocha框架中使用backstopjs断言失败

[英]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.

相关问题 浏览器中的Mocha:如何使用chai.assert获取报告 - Mocha in the browser: How to get a report using chai.assert 检查数组是否是另一个数组的子集,并使用js / chai / mocha在断言失败的情况下最后列出所有差异 - Check if array is a subset of another array and list all the differences at the end with an assert failure using js/chai/mocha 使用 Mocha 和 Chai 断言 RegExp - Assert RegExp with Mocha and Chai 使用Puppeteer,Mocha和Chai在html标记属性中存在文本 - Assert presence of text in an html tag attribute using Puppeteer, Mocha and Chai 困惑于如何正确声明KeystoneJS模型保存错误与Mocha + Chai - confused on how to properly assert a keystoneJS model save error with mocha + chai 我怎么能在使用mocha和chai的`new constructor()`时断言抛出 - how can I assert throw when `new constructor()` with mocha and chai 如何使用 Mocha/Chai/Protractor 单击复选框 - How to click on a checkbox using Mocha/Chai/Protractor 如何使用 mocha、chai 和量角器等待元素 - How to wait for element using mocha, chai & protractor 如何使用 selenium 与 Node.js 和 Chai/Mocha 框架执行向下滚动 - How to perform scroll down using selenium with Node.js and Chai/Mocha framework 如何使用 chai 在 protractor 中断言 sendkeys? - How to assert sendkeys in protractor using chai?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM