在Jest中:在setupTestFrameworkScriptFile中,我可以访问当前正在执行的测试文件的名称/文件名吗?

时间:2019-02-21 17:00:03

标签: node.js testing jestjs

在许多测试中,我创建了一个新的slqite数据库,并希望将测试文件的名称用作sqlite DBname。这样,我所有的数据库测试都相互隔离。

作为一个相关的问题:我希望我的setupTestFrameworkScriptFile能够从测试中读取配置项(对象)。是否有将这些配置从测试传递到TestFramework的标准方法?

这里是一个示例: 在myclass.test.js中:

// "tell" the setup file I'm named 'myclass'
global.testId = function () {
  return "myclass"
}

setupTestFrameworkScriptFile中:

beforeAll(async () => {
// if the test supports this method
if (typeof testId === 'undefined') {
    return
}
// create an sqlite DB with that name
_createAndSyncDb(testId)

相反,我希望setupTestFrameworkScriptFile中的代码从Jest环境中读取文件名,从而消除了对test和setupTestFrameworkScriptFile都知道先前已达成共识的需求名为testId的方法。

0 个答案:

没有答案