0

如何用 commonbeforeAll和编写自己的 Jest 预设afterAll

我很困惑,似乎没有相关文档。

4

1 回答 1

0

您可以通过这种方式扩展环境:

笑话配置:

module.exports = {
    testEnvironment: './suites/future/jest.myEnv.js',
};

jest.myEnv.js: _

const NodeEnvironment = require('jest-environment-node');

const start = async () => {
    console.log('START');
};

const stop = async () => {
    console.log('STOP');
};

class TestEnvironment extends NodeEnvironment {
    constructor(config) {
        super(config);
    }

    async setup() {
        await super.setup();
        await start();
    }

    async teardown() {
        await stop();
        await super.teardown();
    }

    runScript(script) {
        return super.runScript(script);
    }
}

module.exports = TestEnvironment;

于 2020-12-15T12:09:02.913 回答