是否有一种方法仅对于某些测试('it'块)不执行beforeEach函数,

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

是否有一种方法仅对某些测试('it'块)不执行beforeEach函数。

我有一个带有aftereach函数的量角器清理文件,该函数应该在每个测试用例之后运行。有没有一种方法可以在某些测试用例('it'块)中不执行它们。

afterEach(() => {
    common.performance.captureMemory();
    replay.cleanReplay();
    dialog.cleanupDialog(); // Will also close search page source selector dialog if open
    pinboards.closeVizContextIfOpen();
    common.util.dismissNotificationIfPresent();
    formula.closeFormulaEditorIfOpen();
    common.util.ensureLoggedInAsDefaultUser();
    common.util.clearStickerSelection();
    common.util._uniqueNameSeed = -1;
});

I tried this:
global.defaultJasmineAfterEach = () => {
    common.performance.captureMemory();
    replay.cleanReplay();
    dialog.cleanupDialog(); // Will also close search page source selector dialog if open
    pinboards.closeVizContextIfOpen();
    common.util.dismissNotificationIfPresent();
    formula.closeFormulaEditorIfOpen();
    common.util.ensureLoggedInAsDefaultUser();
    common.util.clearStickerSelection();
    common.util._uniqueNameSeed = -1;
};

global.overrideAfterEachOnce = (fn) => {
    global.jasmineAfterEach = fn;
};

global.jasmineAfterEach = defaultJasmineAfterEach;

// This beforeEach block will run after every test, we use this to perform some cleanup that might
// be necessary before next test can run.
afterEach(() => {
    global.jasmineAfterEach();
    if (global.jasmineAfterEach !== global.defaultJasmineAfterEach) {
        global.jasmineAfterEach = global.defaultJasmineAfterEach();
    }
});```

Thanks in advance. :)
javascript jasmine protractor
1个回答
0
投票

beforeEach和afterEach的范围在“ describe()”内)>

describe('title', () => { 

    beforeEach(...)
    it(...)
    it(...)

})

所以也许您想将不同的“ it”限定在不同的“ describe”上?

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