Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongoose = require('mongoose'),
- User = require('../../models/user');
- const mongoUrl = 'mongodb://xxxxxxxxxxx';
- describe('/test', function() {
- before('connect', function() {
- return mongoose.createConnection(mongoUrl);
- });
- beforeEach(async function(done) {
- try {
- await User.remove({}); // <-- This doesn't work
- chai.request('http://localhost:3000')
- .post('/api/test')
- .send(something)
- .end((err, res) => {
- if (err) return done(err);
- done();
- });
- } catch (error) {
- done(error);
- }
- });
- });
- Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
- ...
- db.close();
- return new Promise((resolve) => {
- db.on('disconnected', () => {
- console.log('***************************************Mongoose CONNECTION TERMINATED');
- resolve('user ready');
- });
- });
- ...
- describe('something', () => {
- it('should do something and change it back', async () => {
- try {
- // change user password
- let re1 = await chai.request(app)
- .post('/users/edit')
- .set('authorization', `Bearer ${token}`)
- .send({
- username: 'user@domain.com',
- password: 'password6',
- });
- expect(re1.statusCode).to.equal(200);
- // change password back since before hook not working
- let re2 = await chai.request(app)
- .post('/users/edit')
- .set('authorization', `Bearer ${token}`)
- .send({
- username: 'user@domain.com',
- password: 'password6',
- passwordNew: 'password',
- passwordConfirm: 'password',
- });
- expect(re2.statusCode).to.equal(200);
- } catch (error) {
- // error stuff here
- }
- });
Add Comment
Please, Sign In to add comment