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

Testing #45

Open
Joepock123 opened this issue May 29, 2020 · 2 comments
Open

Testing #45

Joepock123 opened this issue May 29, 2020 · 2 comments

Comments

@Joepock123
Copy link

First up awesome testing on the BE, well done. I referenced yours a lot!

Assertions: there are a couple of useful ones that you could use:

  1. expect.assertions(number) verifies that a certain number of assertions are called during a test. This is often useful when testing asynchronous code, in order to make sure that assertions in a callback actually got called.`
  2. .toHaveProperty(keyPath, value?) to check if property exists for an object (you can also check the value).

A describe block can be used to group tests. N.B this will affect the scope of your test when using beforeEach, afterAll etc.

describe("What tests are you grouping?", () => {
 test("I am test 1"()=>{...})	
})

Katia mentioned it might be nice to split out the model and handlers testing into seperate files. Looking for a solid example as a reference point and will add it when I see something worth following!

I'm sure you do this in your CI workflow but you can add a --coverage flag on the jest test script if you want a summary of code coverage.

@Roger-Heathcote
Copy link
Contributor

Thanks @Joepock123 . I've seen describe used in other people's tests but didn't understand what it actually did. As for splitting them out I'd love to but I started with them all in separate files and quickly ran into serious concurrency issues as all of our tests use the database. Right now all our route tests are actually integrations tests so I think I need to figure out how to use nock with supertest to mock out the database calls and turn them into unit tests. Oh for another week or two eh!

@Joepock123
Copy link
Author

Ye describe is just a bit of sugar for organization! Interested that you tried separating out the files. Hopefully we'll still be in the QA Slack channel to keep on finger on the pulse!

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

No branches or pull requests

2 participants