fix: Mandate assertion count in test which could otherwise false-positive. (#1983)

This was something I just happened to spot, though further investigation is
likely necessary to determine if other similar cases can be discovered.

This fixes this test to `expect` the number of additional `expectations we
have expressed for it: 2.

Testing errors in `catch`es of `Promise` chains necessitates the use of
`expect.assertions(n)` where `n` is the number of assertions declared in
that particular test.

Without this `expect`ation clearly defined, a resolved `Promise` will not
result in the assertion being tested.  For example, if the `query` passed to
this test was a query against a type in the schema (i.e. `query: 'foo'` was
replaced with `query: { query: '{ testString }' }`) the desired error would
not be produced, but the test would still pass.  I'm not saying that's
likely, but there's certainly the possibility that (given fault code)
something else in the plumbing could cause that Promise to resolve.

Ref: https://jestjs.io/docs/en/tutorial-async#error-handling
This commit is contained in:
Jesse Rosenberger 2018-11-22 13:02:51 +02:00 committed by GitHub
parent 87ff25b2df
commit 93489b7941
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,6 +38,8 @@ describe('runHttpQuery', () => {
const noQueryRequest = Object.assign({}, mockQueryRequest, {
query: 'foo',
});
expect.assertions(2);
return runHttpQuery([], noQueryRequest).catch((err: HttpQueryError) => {
expect(err.statusCode).toEqual(400);
expect(err.message).toEqual('Must provide query string.');