为什么我的Mocha / Chai测试会带来误报?

时间:2018-12-05 16:06:21

标签: javascript node.js mocha chai

作为这个问题的先兆,我是Node,JS,Mocha和Chai的新手!

我有一组使用npm run start运行的测试,其中“ start”在Package.json文件中定义了一个脚本:

  "devDependencies": {
    "chai": "^3.5.0",
    "chai-as-promised": "^7.1.1",
    "cli-color": "^1.1.0",
    "concurrently": "^3.1.0",
    "mocha": "^5.2.0"
  },
  "dependencies": {
    "body-parser": "^1.16.1",
    "cors": "^2.8.1",
    "express": "^4.14.0",
    "moment": "^2.18.1",
    "superagent": "^3.3.2"
  }

这是我的考试:

const expect = require('chai').expect;
const screenshotFolder = 'puppeteer/test/screenshots';

module.exports = async(page) => {

  const frame = page.frames().find(frame => frame.name() === 'iframe');

  const allChoicesButton = await frame.$('.statement a.all-choices');
  await allChoicesButton.click({});

 
    const saveYourChoicesButton = await frame.$('.button.permissions-block__submit');
    await saveYourChoicesButton.click({});

 try {
    const confirmationMessageText = await frame.$eval('.submission-response__copy > p', e => e.textContent);

    describe('User can choose all', function() {
      it('Click choose all and display a confirmation message', function(done) {
        expect(confirmationMessageText).to.equal('Thank you. Your choices have been updatedx.').
        notify(done)
      });
    });

  } catch (err) {
    await page.screenshot({
      path: screenshotFolder + '/confirmationMessageText.png',
      fullPage: true
    });
  }
};

我有意在'updatedx'中添加了'x',所以它失败了...。因此,我确定已经问过100次了,但是由于没有抛出错误,我不清楚它为什么通过以及为什么打印屏幕截图。

谢谢。

1 个答案:

答案 0 :(得分:0)

我现在已经意识到错误,将frame。$ eval替换为frame。$,这已经解决了问题。