Skip to content

Promises support #14

@doomsower

Description

@doomsower

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions