使用 cypress-plugin-snapshots returns .toMatchSnapshot 不是函数

Using cypress-plugin-snapshots returns .toMatchSnapshot is not a function

我正在尝试使用 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(和 Cypress)都比较陌生,所以我不确定我做错了什么。如果有人有解决此问题的经验,我将不胜感激。

您只需要用 expect:

包裹您的对象
expect(expectedData).toMatchSnapshot()