使用cypress-plugin-snapshots返回.toMatchSnapshot不是一个函数

问题描述 投票:0回答:1

我正在尝试使用cypress-plugin-snapshots来获取JavaScript对象的一些快照。

我已经按照https://www.npmjs.com/package/cypress-plugin-snapshots上的配置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(和赛普拉斯)都比较陌生,所以我不确定它到底是做错了什么。如果有人有经验对这个问题进行排序,我会非常感激一些意见。

plugins snapshot cypress
1个回答
1
投票

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

expect(expectedData).toMatchSnapshot()
© www.soinside.com 2019 - 2024. All rights reserved.