属性 'matchImageSnapshot' 在类型 'cy & EventEmitter' 上不存在

Property 'matchImageSnapshot' does not exist on type 'cy & EventEmitter'

我按照概述配置了插件 (https://github.com/jaredpalmer/cypress-image-snapshot),但 cypress 无法识别它。如果我在 cy.matchImageSnapshot(); 行前面添加 @ts-ignore,插件就可以工作,但我宁愿能够正确配置框架,这样 cypress 就不会抱怨。 有什么想法吗?

index.js:

const cucumber = require('cypress-cucumber-preprocessor').default;
const browserify = require('@cypress/browserify-preprocessor');
const resolve = require('resolve');
const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin');

module.exports = (on, config) => {
    const options = {
        ...browserify.defaultOptions,
        typescript: resolve.sync('typescript', { baseDir: config.projectRoot })
    };
    on('file:preprocessor', cucumber(options));
    addMatchImageSnapshotPlugin(on, config);
};

commands.js

import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';
addMatchImageSnapshotCommand();

首先,您需要为 TypeScript 类型检查添加 @types/cypress-image-snapshot 包。

然后在 tsconfig.jsoncompilerOptions.types 数组中添加 cypress-image-snapshot