【发布时间】: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