如何解决TypeError: cy.document(...).toMatchSnapshot不是一个函数?

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

我试图在我的页面上使用Cypress和Cypress.toMatchSnapshot为我的e2e测试做快照测试。cypress-plugin-snapshots......。.

但我得到了这个错误 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__/*"
    ]
}

首页.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个回答
1
投票

只是有同样的问题。你的代码应该是。

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

注意 expect

© www.soinside.com 2019 - 2024. All rights reserved.