Skip to content

tobi makes 500 error for later calls #77

Description

@nagyv

I write mocha tests using tobi to test my express app. E.g. this is a part of my tests:

describe('Registration', function(){
  var mailer_send;
  helper.db.connect();
  beforeEach(function(){
    mailer_send = sinon.stub(mailer, "send");
  });
  afterEach(function(){
    mailer.send.restore();
  });
  helper.db.clear_collection('users');
  helper.db.clear_collection_after('users');
  it('opens registration page', function(done){
    helper.browser.get('/auth/register', function(res, $){
      res.should.have.status(200);
      $('form#registrationForm').should.have.length(1);
      $('form#registrationForm').should.have.one('input[name="password"]');
      $('form#registrationForm').should.have.one('input[name="password2"]');
      $('form#registrationForm').should.have.one('input[name="email"]');
      $('form#registrationForm').should.have.one('input[name="name"]');
      done();
    });
  });
  it('creates new user', function(done){
/*    helper.browser.post('/auth/register', {body: $.param({
      name: 'testlogin',
      email: 'valid@example.com',
      password: 'password',
      password2: 'password'
      })},
      function(res, $){  
        mailer_send.callCount.should.be.equal(2);
        res.should.have.status(200);
        statusapp.Users.length.should.equal(1);
        helper.db.with_collection('users', function(err, collection){
          collection.count({name: 'testlogin', active: false}, function(err, num){
            num.should.be.equal(1);
            done();
          });
        });
      }
    );*/
  });
  describe('fails', function(){
    it('for too short password', function(done){
      helper.browser.post('/auth/register', {body: $.param({
        name: 'testlogin',
        email: 'valid@example.com',
        password: 'pa',
        password2: 'pa'
        })},
        function(res, $){  
          res.statusCode.should.equal(200);
          done();
        }
      );
    });
  });
});

Where helper.browser is a tobi.createBrowser(8000, "localhost");

As you can see there is a tobi called commented out. This way all the tests pass. On the other hand if I delete the comments, the last test fails with 500 error. I've tried to investigate the issue, and could not find anything useful, as even my route callbacks are not called. As already said, I would like to test an express based app with mocha.

What can go wrong here?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions