Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promises support #14

Open
doomsower opened this issue Mar 21, 2018 · 1 comment
Open

Promises support #14

doomsower opened this issue Mar 21, 2018 · 1 comment

Comments

@doomsower
Copy link

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?

@prettymuchbryce
Copy link

For anyone else who lands here, it looks like jest supports data-driven tests natively now.

http://jestjs.io/docs/en/api#testeachtable-name-fn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants