vow icon indicating copy to clipboard operation
vow copied to clipboard

Add error message to output when assertStatus fails with 400 or 500

Open MZanggl opened this issue 6 years ago • 1 comments

Proposed changes

Imagine a test like this

test('can create threads', async ({ client }) => {
  const response = await client.post('/threads').send({
    title: 'test title',
    body: 'body',
  }).end()

  response.assertStatus(200)
})

If there is something wrong, the output from the tests is simply

expected 500 to equal 200
  500 => 200

So in order to find out what is the issue you have to go back to the test and add the following before the assertStatus line.

console.log(response.error)

This can be especially cumbersome after a refactoring, or in TDD in general.

With the changes the output will now be (for 4xx and 5xx) for example

(Unique constraint error xxx): expected 500 to equal 200
  500 => 200

Types of changes

What types of changes does your code introduce?

Put an x in the boxes that apply

  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • [x] I have read the CONTRIBUTING doc
  • [x] Lint and unit tests pass locally with my changes
  • [x] I have added tests that prove my fix is effective or that my feature works.
  • [ ] I have added necessary documentation (if appropriate)

Further comments

I added the this.status >= 400 restriction to avoid common mistakes like checking for 200 when really you wanted to check for 204 (same with 3xx for redirects).

MZanggl avatar Oct 21 '19 12:10 MZanggl

Coverage Status

Coverage increased (+0.1%) to 81.238% when pulling eed00b9db82acf1530f573e02692256b8a713153 on MZanggl:feature/assert-status-error into 4a461e2144c4ea8bf9b7a5477916cb81c029dc63 on adonisjs:develop.

coveralls avatar Oct 21 '19 12:10 coveralls