Promises support
Opened this issue · 1 comments
I just tried Sazerac and it looks awesome. Unfortunately, I couldn't make it work for a very common test scenario of mine, which look something like this (I use Jest):
beforeAll(someFunctionThatReturnsPromise);
beforeEach(anotherAsyncFunc);
beforeEach(afterEachAsyncToo);
describe('resovers chain', () => {
beforeEach(asyncFuncForAGroupOfTests);
it('should do some async check', async () => {
const result = await testedAsyncFunc(givenArgs);
expect(result).toBeDefined();
});
});
First I tried something like:
const run = someAsyncFunc
test(run, () => {
given({ days: 1 })
.assert('something about days', async (r) => {
expect(r).toHaveProperty('someprop', 7);
});
});
This failed because assert invoked jest test in sync manner.
beforeAll(someFunctionThatReturnsPromise);
beforeEach(anotherAsyncFunc);
beforeEach(afterEachAsyncToo);
const run = (vars: Variables) => asyncFunc(query, vars);
const promisify = (assertFn: (value: any) => void) => (p: Promise<any>) => p.then(assertFn);
test(run, () => {
given({ days: 1 })
.assert('something about days', promisify((r) => {
expect(r).toHaveProperty('data.lastMeasurements', null);
}));
})
This worked for some tests, but failed for some others, because global beforeEach
didn't fire, I guess. Probably I could promisify beforeEach
too and attach it to each given
TestCase, but this way all the clarity that sazerac gives to sync test cases will be gone.
I checked sazerac source code and it seems that adding async support will require huge changes. So this is too much for me to make a PR. Besides, I'm only familiar with jest.
So is there any chance you could add Promises support to sazerac?
For anyone else who lands here, it looks like jest supports data-driven tests natively now.