【问题标题】:How to fix TypeError: cy.document(...).toMatchSnapshot is not a function?如何修复 TypeError:cy.document(...).toMatchSnapshot 不是函数?
【发布时间】:2019-05-27 02:33:20
【问题描述】:

我正在尝试使用 Cypress 和 cypress-plugin-snapshots 在我的页面上对我的 e2e 测试进行快照测试。

但是我收到了这个错误TypeError: cy.document(...).toMatchSnapshot is not a function。

这是我的配置:

插件/index.js

const { initPlugin } = require('cypress-plugin-snapshots/plugin');

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  initPlugin(on, config);
  return config;
}

支持/index.js

import 'cypress-plugin-snapshots/src/commands';

cypress.json

{
    "ignoreTestFiles": [
        "**/__snapshots__/*",
        "**/__image_snapshots__/*"
    ]
}

home.spec.js

context('Querying', () => {
    beforeEach(() => {
        cy.server();
        cy.fixture('user.json').as('userJSON');
        cy.route('GET', 'users?id=*', '@userJSON').as('getUser');
        cy.visit('http://localhost:4200/1');
    })

    it.only('LANDING - Snapshot test', () => {
        cy.wait(['@getUser']);
        cy.document().toMatchSnapshot()
    });
})

【问题讨论】:

    标签: angular angular7 e2e-testing cypress


    【解决方案1】:

    刚刚遇到同样的问题。你的代码应该是:

    expect(cy.document()).toMatchSnapshot()
    

    注意expect

    【讨论】:

      【解决方案2】:

      你有错误的导入。应该是:

      import 'cypress-plugin-snapshots/commands';
      

      而不是

      import 'cypress-plugin-snapshots/src/commands';
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-02
        • 2019-10-28
        • 2020-09-12
        • 2019-05-30
        • 2019-10-23
        • 2019-06-13
        • 2021-10-07
        • 2019-09-28
        相关资源
        最近更新 更多