Jasmine Async Test Generation
Solution 1:
Take a look at Defining Tests. The doc says:
Tests must be defined synchronously for Jest to be able to collect your tests.
This is the principle for defining test cases. Which means the it
function should be defined synchronously. That's why your second example doesn't work.
Some I/O operations should be done in beforeAll
, afterAll
, beforeEach
, afterEach
methods to prepare your test doubles and fixtures. The test should be isolated from the external environment as much as possible.
If you must do this, maybe you can write the dynamically obtained testHelper
function to a static js file, and then test it in a synchronous way
Solution 2:
As it was noted, describe
serves to group tests.
This can be achieved with beforeAll
. Since beforeAll
should be called any way, it can be moved to testPromise
:
constprepareHelpers = (testFn) => {
beforeAll(() => {
...
return helper.then(testFn);
})
}
describe('Async describe approach', () => {
let testHelper;
prepareHelpers(helpers => { testHelper = helpers.testHelper });
...
Post a Comment for "Jasmine Async Test Generation"