【问题标题】:Using cypress-plugin-snapshots returns .toMatchSnapshot is not a function使用 cypress-plugin-snapshots 返回 .toMatchSnapshot 不是函数
【发布时间】:2019-04-04 06:29:03
【问题描述】:

我正在尝试使用 cypress-plugin-snapshots 为 JavaScript 对象拍摄一些快照。

我已按照https://www.npmjs.com/package/cypress-plugin-snapshots 上的 Configure Cypress.io 说明进行操作,但是当我运行测试(如下)时,我收到以下错误

1) Check snapshots Should match snapshot: TypeError: expectedData.toMatchSnapshot is not a function at Context.<anonymous> (https://www.bbc.com/__cypress/tests?p=cypress/integration/data_driven.js-917:24:18)

我的测试文件是:

describe('Check snapshots', function () {
    it('Should match snapshot', () => {
    const expectedData = {
      fonts: 
       [ { familyName: 'Helvetica', isCustomFont: false, glyphCount: 10 },
         { familyName: 'Gurmukhi MN', isCustomFont: false, glyphCount: 33 } ]
    }

      expectedData.toMatchSnapshot();
    });
  });

我对 JS(和 Cypress)都比较陌生,所以我不确定我到底做错了什么。如果有人有解决此问题的经验,我将非常感谢您提供一些意见。

【问题讨论】:

    标签: plugins snapshot cypress


    【解决方案1】:

    你只需要用expect包装你的对象:

    expect(expectedData).toMatchSnapshot()
    

    【讨论】:

    • 非常感谢 bkucera,我真的很感激。
    猜你喜欢
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 2013-09-17
    • 2021-03-10
    • 2021-05-03
    • 2017-08-14
    相关资源
    最近更新 更多