can not access global 'allure' object using mocha-allure

这一生的挚爱 提交于 2021-01-28 08:41:25

问题


According to mocha-allure docs, if you want to use allure outside of before/beforeEach you should import the reporter directly. Or once added mocha-allure-reporter will create global allure object with the following API:

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

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

However I followed the example in the docs, but i get Cannot find name 'allure'. , when using it in either the before or afterEach.

test file:

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');
          });
    });

config:

mochaOpts: {
        reporterOptions: {
            reporterEnabled:
                mocha-allure-reporter,
          mochaAllureReporterReporterOptions: {
                targetDir: './reports/allure-results',
            },

回答1:


Try the below one

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

allure is a global identifier, injected by reporter to your code.

Add the following line to the top of your file to tell Typescript about it

declare const allure: any;

Hope it helps you



来源:https://stackoverflow.com/questions/55105020/can-not-access-global-allure-object-using-mocha-allure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!