vitest icon indicating copy to clipboard operation
vitest copied to clipboard

NestJS E2E tests failing when using vitest (when using sequelize query)

Open studiojms opened this issue 6 months ago • 5 comments

Describe the bug

I have a project using NestJS, Sequelize, Sequelize-Typescript, and Testcontainers. The E2E test is responsible for setting up some data and testing an API. By relying on the sequelize-typescript project, when querying some data, the result should be an object populated. It works as desired when using jest, but after converting my tests to vitest, it's not working as expected. My query result is returned with some empty fields (although the object brings the data I want in some hidden property).

{
  subject: Subject {
    dataValues: {
      id: '59a59521-665c-4a21-86ea-8044da9c33ac',
      description: 'test',
      orderId: '56b6f0aa-c592-44d6-b0b7-e02dc1910a03',
      createdAt: 2024-08-19T18:38:18.962Z,
      updatedAt: 2024-08-19T18:38:18.962Z,
      observations: [Array]
    },
    _previousDataValues: {
      id: '59a59521-665c-4a21-86ea-8044da9c33ac',
      description: 'test',
      orderId: '56b6f0aa-c592-44d6-b0b7-e02dc1910a03',
      createdAt: 2024-08-19T18:38:18.962Z,
      updatedAt: 2024-08-19T18:38:18.962Z,
      observations: [Array]
    },
    uniqno: 1,
    _changed: Set(0) {},
    _options: {
      isNewRecord: false,
      _schema: null,
      _schemaDelimiter: '',
      include: [Array],
      includeNames: [Array],
      includeMap: [Object],
      includeValidated: true,
      attributes: [Array],
      raw: true
    },
    isNewRecord: false,
    observations: undefined,
    id: undefined,
    description: undefined,
    orderId: undefined
  }
}

If I try to get subject.id, subject.description or anything, it returns undefined.

What I am missing here? Why did it work with jest?

Reproduction

To reproduce the bug, here's the repo: https://github.com/studiojms/nest-vitest-fhir-sample

The E2E test is here: https://github.com/studiojms/nest-vitest-fhir-sample/blob/main/test/app.e2e-spec.ts

This is the repo with jest setup for E2E (working): https://github.com/studiojms/nest-vitest-fhir-sample/tree/2042a1c32bf5c9e74e352b1bf2f67b07986d9afb

The problem happens at this line when it tries to check the query result: https://github.com/studiojms/nest-vitest-fhir-sample/blob/main/src/subject/subject.service.ts#L30

To execute the project, run:

npm run test:e2e

or

yarn test:e2e

System Info

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M3
    Memory: 68.89 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - ~/.nvm/versions/node/v20.15.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.15.1/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.1/bin/npm
  Browsers:
    Brave Browser: 127.1.68.141
    Chrome: 127.0.6533.120
    Safari: 17.6
  npmPackages:
    @vitest/coverage-v8: ^2.0.5 => 2.0.5 
    vitest: ^2.0.5 => 2.0.5

Used Package Manager

yarn

Validations

studiojms avatar Aug 19 '24 18:08 studiojms