I am testing my Node app with 'chai'. I use sequelize ORM to work with Postgres. The app works fine, except the testing is a trouble.
Here is the code:
import server from '../../server';
import { expect } from 'chai';
import request from 'supertest';
import models from '../../db/models';
describe('Authentication', () => {
describe('DB connection', function() {
beforeEach(function(done) {
models.sequelize.sync({ force: true })
.then(() => {
done();
});
});
it('Creates a user with password', (done) => {
models.User.create({
firstName: 'Tester',
lastName: 'Testosteron',
email: 'testosteron@test.com',
dateOfBirth: '01.01.01'
})
.then((user) => {
models.Local.create({ password: '123456', UserId: 1 })
.then(function(){
done();
})
})
.catch(function(error) {
done(error);
});
});
})
});
The test is passing and creates a user. However I get the following error:
Unhandled rejection SequelizeDatabaseError: relation "Users" does not exist
at Query.formatError (/Users/.../node_modules/sequelize/lib/dialects/postgres/query.js:357:14)
at Query.<anonymous> (/Users/.../node_modules/sequelize/lib/dialects/postgres/query.js:88:19)
at emitOne (events.js:96:13)
at Query.emit (events.js:188:7)
at Query.handleError (/Users/.../node_modules/pg/lib/query.js:143:8)
at Connection.<anonymous> (/Users/.../node_modules/pg/lib/client.js:180:26)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at Socket.<anonymous> (/Users/.../node_modules/pg/lib/connection.js:136:12)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:551:20)
How to fix this error?
Aucun commentaire:
Enregistrer un commentaire