Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:14:48+00:00 2026-06-14T07:14:48+00:00

I keep getting an error in the save() method when I run the test.

  • 0

I keep getting an error in the save() method when I run the test.

var User = require('../../models/user')
, should = require('should');

describe('User', function(){
  describe('#save()', function(){
    it('should save without error', function(done){
      var user = new User({
        username    : 'User1'
        , email     : 'user1@example.com'
        , password  : 'foo'
      });
      user.save(function(err, user){
        if (err) throw err;

        it('should have a username', function(done){
          user.should.have.property('username', 'User1');
          done();
        });
      });
    })
  })

})

here is the error:

$ mocha test/unit/user.js

  ․

  ✖ 1 of 1 test failed:

  1) User #save() should save without error:
     Error: timeout of 2000ms exceeded
      at Object.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:1
61:14)
      at Timer.list.ontimeout (timers.js:101:19)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:14:50+00:00Added an answer on June 14, 2026 at 7:14 am

    You can nest describes but not it tests. Each test is meant to be stand alone so when you are looking through your results you can see where it is failing – on the save or not having the username property. For example in your code above there is no way for it to fail the ‘should save without error’ test as there is no done(). Which is also the reason the code above is timing out: mocha cannot find the done() for the ‘should save without error’ test.

    Being able to nest describes is very powerful though. Within each describe you can have a before, beforeEach, after and afterEach statement. With these you can achieve the nesting that you are attempting above. See the mocha docs for more information if you want to read up on these statements.

    The way I would write what you are trying to achieve is as follows:

    var User = require('../../models/user')
        , should = require('should')
        // this allows you to access fakeUser from each test
        , fakeUser;
    
    describe('User', function(){
      beforeEach(function(done){
        fakeUser = {
          username    : 'User1'
          , email     : 'user1@example.com'
          , password  : 'foo'
        }
        // this cleans out your database before each test
        User.remove(done);
      });
    
      describe('#save()', function(){
        var user;
        // you can use beforeEach in each nested describe
        beforeEach(function(done){
          user = new User(fakeUser);
          done();
        }
    
        // you are testing for errors when checking for properties
        // no need for explicit save test
        it('should have username property', function(done){
          user.save(function(err, user){
            // dont do this: if (err) throw err; - use a test
            should.not.exist(err);
            user.should.have.property('username', 'User1');
            done();
          });
        });
    
        // now try a negative test
        it('should not save if username is not present', function(done){
          user.username = '';
          user.save(function(err, user){
            should.exist(err);
            should.not.exist(user.username);
            done();
          });
        });
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run a very simple integration test and keep getting this error:
I keep getting this error when I try and view my register user page
In Doctrine2.0.6, I keep getting an error: Column VoucherId specified twice. The models in
I'm trying to install a package that uses global-linum-mode and keep getting: error Autoloading
With the following code, I keep getting error C2535 when I compile. It's complaining
I'm trying to code some stuff for a game but I keep getting error
Keep getting this error after inserting a subdatasheet into a query and trying to
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
I keep getting this error and have no idea why. I googled and scanned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.