-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Worker Test Example #126
Comments
I don’t have time to review this today; but you might like to look at the tests in Graphile Starter.l, a few of those involve worker methinks. |
Since the worker tasks are just functions, do you actually want to test the DB infrastructure around them or do you just want to test the function itself? It seems that we could expose it('does things', async (done) => {
const client = /* get client from pool */
const withPgClient = (cb) => cb(client);
const job = mockJob({task_identifier: 'hello', payload: {...payload...}})
const helpers = makeJobHelpers({...options...}, job, {withPgClient});
const spy = jest.spyOn(global.console, 'info');
await hello(job.payload, helpers);
expect(spy.mock.calls[0][4].includes(payloadName)).toBeTruthy();
}); I think it makes sense to include mockJob as part of graphile-worker because the What do you think? |
yeah all i want to test is that given a certain payload to a task the things I want it to do are done. I want the db stuff as extracted away as possible. also I had a lot of flakiness in my tests until I added |
You could just do |
updated to waaaay better way of writting spy tests
|
Just following up on this thread as I want to test one of my workers as well. Did any tooling end up being exposed to support mocks so that the tests don't require a database connection? (I saw @benjie's thought about exposing (Thank you for the great library!) |
|
Was looking through the code for how to test as its not really clear from the readme. Here is something I hacked up.
Would appreciate any feedback on it. Once its decent I would be happy to make a pr. This example is for jest with @babel/preset-env
Thanks for the great lib!
The text was updated successfully, but these errors were encountered: