Saturday, 15 April 2017

Testing Sequelize with Mocha

I have a strange issue , i'm testing my Node/Express Application with Mocha and Chai, and I have errors if i drop the table after my test:

enter image description here

here's the code who generate the error , i already tried async/await and done it's not working either

const chaiHttp = require('chai-http')
const chai = require('chai')

const app = require('../../../api/app')
const db = require('../../../db/collections')
const CustomerList = db.CustomerList

chai.use(chaiHttp)
const expect = chai.expect

describe('CustomersRouter', () => {

  before(() => {
    CustomerList.sync() // also tried with {force: true}
  })

  beforeEach(() => {
    const testObject = {
      firstName: 'firstname',
      id: 1,
      lastName: 'lastname',
      mail: 'uu.dd@gmail.com',
      nationalite: 'de',
      status: 'DONE'
    }
    CustomerList.create(testObject)
  })

  afterEach(() => {
   CustomerList.truncate()
  })

  after(() => {
   CustomerList.drop()
  })

  describe('GET /customers', () => {
    it('should be json', () => {
      return chai.request(app).get('/customers')
        .then(res => {
         expect(res.type).to.eql('application/json')
       })
    })
})

for further infos here's the code repository : https://github.com/zelazna/NodeApi/blob/develop/test/api/routes/customersRouter.spec.js

what am I doing wrong here?



via Constantin Guidon

No comments:

Post a Comment