簡體   English   中英

如何使用來自不同出口的 this.skip() function

[英]How to use this.skip() from different exports function

我正在使用 mocha 運行測試,我想以編程方式跳過測試。 我遇到了this.skip()。 我想根據條件跳過測試,但我看到錯誤“TypeError:this.skip is not a function”

另外我不是this.skip(),這里指的是哪個object?

這是我的規格文件

test.spec.js

const expect = require('chai').expect;
const Mochaexport = require('../cypress/support/mochaExport');
let mochaExp = new Mochaexport(); 

describe('mocha test', function() {
    it('runs mocha test', function() {
        mochaExp.skipTest("2020");
        expect(true).to.equal(true);
    })
})

mochaExport.js

const { expect } = require("chai");

module.exports = function() {

    this.skipTest = function(Year) {
        if(Year == "2020") {
            this.skip();
        } else {
            expect(Year).to.equal(2021);
        }
    }
}

我正在尋找在 export.Found 解決方案中運行語句 this.skip 如何執行此操作,

我將此傳遞給了我在導出中提到的 function 並稱為跳過,這是跳過測試。

這是代碼片段

const expect = require('chai').expect;
const Mochaexport = require('../cypress/support/mochaExport');
let mochaExp = new Mochaexport(); 

describe('mocha test', function() {
    it('runs mocha test', function() {
        mochaExp.skipTest("2020", this);
        expect(true).to.equal(true);
    })
})
const { expect } = require("chai");

module.exports = function() {

    this.skipTest = function(Year, context) {
        if(Year == "2020") {
            context.skip();
        } else {
            expect(Year).to.equal(2021);
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM