Saturday, 15 April 2017

Mocha with chai-http starting server during a test

I'm trying to do a API test (mocha, chai, chai-http) but when I use the agent with a nested agent.get it ends up starting my server and the tests do not run correctly. For example, during the test I see:

API started Access URLs: Localhost: http://localhost:8100 LAN: http://10.0.1.12:8100

Typically I don't see the server start when running them tests with this chain chai.request.get.end. Here is my failing test:

    it('it should GET session status for an authenticated user', (done) => {
    let user = {
      email: 'jrr@xx.net',
      password: "xx"
    };
    let agent = chai.request.agent(server);
    agent
      .post('/api/v1/auth/signin')
      .send(user)
      .then(res1 => {
        res1.should.have.cookie('connect.sid');
        res1.should.have.status(200);

        return agent.get('/api/v1/auth/checksession')
        .then(r2 => {
          r2.should.have.status(200);
          done();
        });
      })
      .catch((error) => {
        throw error;
      });
    });
   });



via Jason Leach

No comments:

Post a Comment