有没有办法只针对某些测试('it' 块)不执行 beforeEach 函数
Is there a way to NOT execute beforeEach function only for certain tests ('it' blocks)
有没有办法只对某些测试('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. :)
beforeEach 和 afterEach 的范围在 "describe()"
内
describe('title', () => {
beforeEach(...)
it(...)
it(...)
})
所以也许您想在不同的 "describe" 上限定不同的 "it"?
我认为您应该查看 this answer,但对我来说最简单的方法如下。
不要将它放在配置文件中,而是创建一个名为 afterEach.js
的单独文件
afterEach.js
module.exports = function () {
afterEach(() => {
console.log('afterEach complete')
})
}
对于任何需要在描述块中使用 require('./afterAll')();
之后的规范
spec.js
describe('angularjs homepage todo list', function () {
require('./afterEach')();
it('should add a todo', function () {
expect(true).toBe(false);
});
it('should add a todo2', function () {
expect(true).toBe(true);
});
});
有没有办法只对某些测试('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. :)
beforeEach 和 afterEach 的范围在 "describe()"
内describe('title', () => {
beforeEach(...)
it(...)
it(...)
})
所以也许您想在不同的 "describe" 上限定不同的 "it"?
我认为您应该查看 this answer,但对我来说最简单的方法如下。 不要将它放在配置文件中,而是创建一个名为 afterEach.js
的单独文件afterEach.js
module.exports = function () {
afterEach(() => {
console.log('afterEach complete')
})
}
对于任何需要在描述块中使用 require('./afterAll')();
之后的规范
spec.js
describe('angularjs homepage todo list', function () {
require('./afterEach')();
it('should add a todo', function () {
expect(true).toBe(false);
});
it('should add a todo2', function () {
expect(true).toBe(true);
});
});