question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter: behavior of e2e test differs from true http request

See original GitHub issue

I’m submitting a…


[ ] Regression 
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

I register a global filter SequelizeValidatorFilter

import { ExceptionFilter, Catch, HttpStatus } from '@nestjs/common'
import { Sequelize } from 'sequelize-typescript'

@Catch(Sequelize.ValidationError)
export class SequelizeValidatorFilter implements ExceptionFilter {
    catch(exception: typeof Sequelize.ValidationError, response: any) {
        response
            .status(HttpStatus.CONFLICT)
            .json({
                error: exception.message,
                message: exception.errors.map(error => error.message),
            })
    }
}

then, I ran the application and used Swagger UI sent a true request, here is the result

{
  "error": "Validation error",
  "message": [
    "username must be unique"
  ]
}

and statusCode is 409

however, when I use npm run test:e2e, the statusCode is 500, the e2e-spec.ts:

it('Post /user conflict', () => {
        return request(app.getHttpServer())
            .post('/user')
            .send({
                username: 'Hex',
                email: 'hexileee@gmail.com',
                name: 'Hex,
                password: '123456'
            })
            .expect(HttpStatus.CONFLICT)
            .expect(res => {
                const resp = res.body as ValidationErrorDto
                expect(resp.error).toBe('Validation error')
                expect(resp.message).toHaveLength(1)
            })
    })
})

the console:

expected 409 "Conflict", got 500 "Internal Server Error"

      at Test.Object.<anonymous>.Test._assertStatus (../node_modules/supertest/lib/test.js:266:12)
      at Test.Object.<anonymous>.Test._assertFunction (../node_modules/supertest/lib/test.js:281:11)
      at Test.Object.<anonymous>.Test.assert (../node_modules/supertest/lib/test.js:171:18)
      at Server.assert (../node_modules/supertest/lib/test.js:131:12)
      at Object.onceWrapper (../events.js:254:19)
      at Server.emit (../events.js:159:13)
      at emitCloseNT (../net.js:1689:8)
      at process._tickCallback (../internal/process/next_tick.js:152:19)

Environment


Nest version: 4.6.6
    
Jest version: 21.1.10,
> ts-jest: 21.2.4
 
For Tooling issues:
- Typescript version: 2.7.2
- Node version: 9.3.0
- Platform:  MacOS 10.13.4

Others:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilmysliwieccommented, Apr 29, 2018

Therefore you need to do the same inside your tests. Once you created a Nest instance using createNestApplication(), you have to bind appropriate filters.

0reactions
lock[bot]commented, Sep 25, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AngularJS e2e testing ng-table filter - Stack Overflow
The problem is when I type in a filter input box (provided by ng-table) the listing in my tests is not automatically updated, ......
Read more >
'Why Didn't This Get Tested!?' E2E Testing with Live User Data
Unfortunately, these tests are subjective, based on the QA teams' best-educated guesses. They're stuck trying to predict what real-life user ...
Read more >
Just Say No to More End-to-End Tests - Google Testing Blog
An integration test takes a small group of units, often two units, and tests their behavior as a whole, verifying that they coherently...
Read more >
REST API Testing Strategy: What Exactly Should You Test?
The API layer of any application is one of the most crucial software components. Here's a technical look at how we test our...
Read more >
End-to-End testing with Angular and Knockout - Scott Logic Blog
For example, it will automatically wait for $http asynchronous requests to finish, which makes coding e2e tests a lot simpler.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found