mirror of
https://github.com/vale981/apollo-server
synced 2025-03-05 09:41:40 -05:00
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:
parent
87ff25b2df
commit
93489b7941
1 changed files with 2 additions and 0 deletions
|
@ -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.');
|
||||
|
|
Loading…
Add table
Reference in a new issue