无法使用 mocha-allure 访问全局“诱惑"对象 [英] can not access global 'allure' object using mocha-allure
问题描述
根据 mocha-allure 文档,如果您想在 before/beforeEach 之外使用 allure,则应直接导入报告器.或者一旦添加 mocha-allure-reporter 将使用以下 API 创建全局诱惑对象:
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
但是我遵循了文档中的示例,但是在 before 或 afterEach 中使用它时,我得到 Cannot find name 'allure'.
.
However I followed the example in the docs, but i get Cannot find name 'allure'.
, when using it in either the before or afterEach.
测试文件:
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',
},
推荐答案
试试下面的一个
const allure = require('mocha-allure-reporter');
allure 是一个全局标识符,由报告器注入到您的代码中.
allure is a global identifier, injected by reporter to your code.
将以下行添加到文件顶部以告诉 Typescript
Add the following line to the top of your file to tell Typescript about it
declare const allure: any;
希望对你有帮助
这篇关于无法使用 mocha-allure 访问全局“诱惑"对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!