Sequelize doesn’t works well with tests

I have some tests and, if I run only that test individually, it works normally, but if I run all the tests, it keeps printing No description found for "Users" table. Check the table name and schema; remember, they _are_ case sensitive., but that doesn’t makes sense, because it doesn’t happen if I only run that test block.

My tests:

import { Sequelize } from 'sequelize-typescript'
import bcrypt from 'bcrypt'
import request from 'supertest'
import User from '../../src/Models/UserModel'
import app from '../../src/app'
import { setupSequelize } from '../setup/sequelizeSetup'
import RefreshTokenService from '../../src/Services/RefreshTokenServices'
import { signJwt } from '../../src/utils/JwtUtils'

describe('User Controller', () => {
  let user: User
  let sequelize: Sequelize

  beforeEach(async () => {
    sequelize = await setupSequelize()
    user = await User.create({
      email: '[email protected]',
      name: 'teste',
      password: 'teste',
    })
  })

  describe('Register User', () => {
    it('Deve registrar um usuário com sucesso', async () => {
      const response = await request(app)
        .post('/user/register')
        .send({
          name: 'teste',
          email: '[email protected]',
          password: 'testeteste',
        })
        .expect(200)

      expect(response.body).toEqual(
        expect.objectContaining({
          message: expect.stringContaining('Usuário Criado com Sucesso'),
        })
      )
    })

    it('Deve retornar erro 400 ao registrar usuário sem nome', async () => {
      const response = await request(app)
        .post('/user/register')
        .send({ email: '[email protected]', password: 'teste' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há o nome do usuário, lembre de adicionar o campo `name`'
          ),
        })
      )
    })

    it('Deve retornar erro 400 ao registrar usuário sem email', async () => {
      const response = await request(app)
        .post('/user/register')
        .send({ name: 'teste', password: 'teste' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há o nome de email, lembre de adicionar o campo `email`'
          ),
        })
      )
    })

    it('Deve retornar erro 400 ao registrar usuário sem senha', async () => {
      const response = await request(app)
        .post('/user/register')
        .send({ name: 'teste', email: '[email protected]' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há senha para registrar-se, lembre de adicionar o campo `password`'
          ),
        })
      )
    })
  })

  describe('Login User', () => {
    beforeEach(async () => {
      const hashedPass = await bcrypt.hash('teste', 10)
      user.update({ password: hashedPass })
    })
    it('Deve logar um usuário com sucesso', async () => {
      const response = await request(app)
        .post('/user/login')
        .send({ email: '[email protected]', password: 'teste' })

      expect(response.body).toEqual(
        expect.objectContaining({
          message: expect.stringContaining('Login realizado com sucesso'),
          token: expect.stringMatching(/.{680,}/),
        })
      )
    })

    it('Deve retornar erro 400 ao logar usuário sem email', async () => {
      const response = await request(app)
        .post('/user/login')
        .send({ password: 'teste' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há o nome de email, lembre de adicionar o campo `email`'
          ),
        })
      )
    })

    it('Deve retornar erro 400 ao logar usuário sem senha', async () => {
      const response = await request(app)
        .post('/user/login')
        .send({ email: '[email protected]' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há senha para registrar-se, lembre de adicionar o campo `password`'
          ),
        })
      )
    })
  })

  describe('Logout User', () => {
    it('Deve deslogar um usuário com sucesso', async () => {
      const newAccessToken = signJwt(user.id, 'Access')
      RefreshTokenService.create(newAccessToken, 1)
      const response = await request(app)
        .get('/user/logout')
        .set('Authorization', `Bearer ${newAccessToken}`)

      expect(response.body).toEqual(
        expect.objectContaining({
          message: expect.stringContaining(
            'Você saiu da sua conta com sucesso'
          ),
        })
      )
    })
  })
})

Sequelize Setup Config:

// tests/setup/sequelize.ts
import { Sequelize } from 'sequelize-typescript'
import Account from '../../src/Models/AccountModel'
import EmailConfirmToken from '../../src/Models/EmailConfirmTokenModel'
import RedefinePasswordTokens from '../../src/Models/RedefinePasswordTokensModel'
import RefreshToken from '../../src/Models/RefreshTokenModel'
import User from '../../src/Models/UserModel'

export const setupSequelize = async () => {
  const sequelize: Sequelize = new Sequelize({
    dialect: 'sqlite',
    storage: ':memory:',
    models: [
      Account,
      EmailConfirmToken,
      RedefinePasswordTokens,
      RefreshToken,
      User,
    ],
    logging: false,
  })
  await sequelize.sync({ force: true })
  return sequelize
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Sequelize doesn’t works well with tests

I have some tests and, if I run only that test individually, it works normally, but if I run all the tests, it keeps printing No description found for "Users" table. Check the table name and schema; remember, they _are_ case sensitive., but that doesn’t makes sense, because it doesn’t happen if I only run that test block.

My tests:

import { Sequelize } from 'sequelize-typescript'
import bcrypt from 'bcrypt'
import request from 'supertest'
import User from '../../src/Models/UserModel'
import app from '../../src/app'
import { setupSequelize } from '../setup/sequelizeSetup'
import RefreshTokenService from '../../src/Services/RefreshTokenServices'
import { signJwt } from '../../src/utils/JwtUtils'

describe('User Controller', () => {
  let user: User
  let sequelize: Sequelize

  beforeEach(async () => {
    sequelize = await setupSequelize()
    user = await User.create({
      email: '[email protected]',
      name: 'teste',
      password: 'teste',
    })
  })

  describe('Register User', () => {
    it('Deve registrar um usuário com sucesso', async () => {
      const response = await request(app)
        .post('/user/register')
        .send({
          name: 'teste',
          email: '[email protected]',
          password: 'testeteste',
        })
        .expect(200)

      expect(response.body).toEqual(
        expect.objectContaining({
          message: expect.stringContaining('Usuário Criado com Sucesso'),
        })
      )
    })

    it('Deve retornar erro 400 ao registrar usuário sem nome', async () => {
      const response = await request(app)
        .post('/user/register')
        .send({ email: '[email protected]', password: 'teste' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há o nome do usuário, lembre de adicionar o campo `name`'
          ),
        })
      )
    })

    it('Deve retornar erro 400 ao registrar usuário sem email', async () => {
      const response = await request(app)
        .post('/user/register')
        .send({ name: 'teste', password: 'teste' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há o nome de email, lembre de adicionar o campo `email`'
          ),
        })
      )
    })

    it('Deve retornar erro 400 ao registrar usuário sem senha', async () => {
      const response = await request(app)
        .post('/user/register')
        .send({ name: 'teste', email: '[email protected]' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há senha para registrar-se, lembre de adicionar o campo `password`'
          ),
        })
      )
    })
  })

  describe('Login User', () => {
    beforeEach(async () => {
      const hashedPass = await bcrypt.hash('teste', 10)
      user.update({ password: hashedPass })
    })
    it('Deve logar um usuário com sucesso', async () => {
      const response = await request(app)
        .post('/user/login')
        .send({ email: '[email protected]', password: 'teste' })

      expect(response.body).toEqual(
        expect.objectContaining({
          message: expect.stringContaining('Login realizado com sucesso'),
          token: expect.stringMatching(/.{680,}/),
        })
      )
    })

    it('Deve retornar erro 400 ao logar usuário sem email', async () => {
      const response = await request(app)
        .post('/user/login')
        .send({ password: 'teste' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há o nome de email, lembre de adicionar o campo `email`'
          ),
        })
      )
    })

    it('Deve retornar erro 400 ao logar usuário sem senha', async () => {
      const response = await request(app)
        .post('/user/login')
        .send({ email: '[email protected]' })
        .expect(400)

      expect(response.body).toEqual(
        expect.objectContaining({
          error: expect.stringContaining(
            'Não há senha para registrar-se, lembre de adicionar o campo `password`'
          ),
        })
      )
    })
  })

  describe('Logout User', () => {
    it('Deve deslogar um usuário com sucesso', async () => {
      const newAccessToken = signJwt(user.id, 'Access')
      RefreshTokenService.create(newAccessToken, 1)
      const response = await request(app)
        .get('/user/logout')
        .set('Authorization', `Bearer ${newAccessToken}`)

      expect(response.body).toEqual(
        expect.objectContaining({
          message: expect.stringContaining(
            'Você saiu da sua conta com sucesso'
          ),
        })
      )
    })
  })
})

Sequelize Setup Config:

// tests/setup/sequelize.ts
import { Sequelize } from 'sequelize-typescript'
import Account from '../../src/Models/AccountModel'
import EmailConfirmToken from '../../src/Models/EmailConfirmTokenModel'
import RedefinePasswordTokens from '../../src/Models/RedefinePasswordTokensModel'
import RefreshToken from '../../src/Models/RefreshTokenModel'
import User from '../../src/Models/UserModel'

export const setupSequelize = async () => {
  const sequelize: Sequelize = new Sequelize({
    dialect: 'sqlite',
    storage: ':memory:',
    models: [
      Account,
      EmailConfirmToken,
      RedefinePasswordTokens,
      RefreshToken,
      User,
    ],
    logging: false,
  })
  await sequelize.sync({ force: true })
  return sequelize
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật