我试图在我的页面上使用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()
});
})
只是有同样的问题。你的代码应该是。
expect(cy.document()).toMatchSnapshot()
注意 expect