无法使用mocha-allure访问全局'诱惑'对象

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

根据mocha-allure文档,如果你想在之前/之前使用诱惑,你应该直接导入记者。或者一旦添加了mocha-allure-reporter,就会使用以下API创建全局诱惑对象:

https://github.com/allure-framework/allure-mocha

https://github.com/allure-examples/mocha-allure-example/blob/master/test/simple.spec.js

但是我按照文档中的示例进行了操作,但是当我在before或afterEach中使用它时,我得到了Cannot find name 'allure'.

测试文件:

require('mocha-allure-reporter');
// const allure = require('mocha-allure-reporter'); // also tried this

describe( 'test', () => {
// code



before(async () => {
  // code here
});


  afterEach('first step', function () {
        const testStep = allure.createStep('initial', () => {
            console.log('create step');
          });
    });

配置:

mochaOpts: {
        reporterOptions: {
            reporterEnabled:
                mocha-allure-reporter,
          mochaAllureReporterReporterOptions: {
                targetDir: './reports/allure-results',
            },
protractor mocha allure
1个回答
0
投票

试试下面的一个

const allure = require('mocha-allure-reporter');

allure是一个全局标识符,由记者注入您的代码。

将以下行添加到文件顶部以告诉Typescript

declare const allure: any;

希望它能帮到你

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