nestjs-asyncapi icon indicating copy to clipboard operation
nestjs-asyncapi copied to clipboard

Adding AsyncApi decorators results in wrong call stack line number for failing tests

Open bakasmarius opened this issue 1 year ago • 1 comments

Describe the bug Adding a decorator from AsyncApi results in the wrong call stack line number for failing tests

To Reproduce Steps to reproduce the behavior:

  1. Create a new Nest project (npx @nestjs/cli@latest new test-call-stack-bug)
  2. Install nestjs-asyncapi (npm i -D nestjs-asyncapi)
  3. Add @AsyncApi() to AppService class
  4. Add a failing test to app.controller.spec.ts:
  describe('root', () => {
    it('should return "Hello World!"', () => {
      expect(appController.getHello()).toBe('Hello World!')
    })

    it('should fail', () => {
      expect(5).toBe(6)
    })
  })
  1. Run the tests (npm test) and notice how the wrong line is marked as the failing one:
 ● AppController › root › should fail

   expect(received).toBe(expected) // Object.is equality

   Expected: 6
   Received: 5

     18 |   describe('root', () => {
     19 |     it('should return "Hello World!"', () => {
   > 20 |       expect(appController.getHello()).toBe('Hello World!')
        |                       ^
     21 |     })
     22 |
     23 |     it('should fail', () => {

     at Object.<anonymous> (app.controller.spec.ts:20:23)

Expected behavior The failing row is shown correctly (which happens if I remove @AsyncApi() decorator from AppService class):


  ● AppController › root › should fail

    expect(received).toBe(expected) // Object.is equality

    Expected: 6
    Received: 5

      22 |
      23 |     it('should fail', () => {
    > 24 |       expect(5).toBe(6)
         |                 ^
      25 |     })
      26 |   })
      27 | })

      at Object.<anonymous> (app.controller.spec.ts:24:17)

Environment

  • Nest version: 10.2.7
  • Node version: 18.18.2
  • Platform: Windows, Linux

Additional context Same thing happens if I add @AsyncApiPub decorator to a method in AppService:

@Injectable()
export class AppService {
  @AsyncApiPub({ channel: 'test', message: { name: 'test', payload: 'test' } })
  getHello(): string {
    return 'Hello World!'
  }
}

bakasmarius avatar Oct 30 '23 09:10 bakasmarius