在许多测试中,我创建了一个新的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
的方法。