Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test stops after when use authenticatedSession #33

Open
kazkondo opened this issue Apr 15, 2018 · 2 comments
Open

Test stops after when use authenticatedSession #33

kazkondo opened this issue Apr 15, 2018 · 2 comments

Comments

@kazkondo
Copy link

const session = require('supertest-session');
const myApp = require('../../app');

describe('Test sample', () => {

  let testSession;
  let authenticatedSession;

  beforeEach( () => {
    testSession = session(myApp);
  });

  it('/member/login', (done) => {
    testSession.post('/member/login')
      .send({ userid: 'test@example.com', password: 'test' })
      .expect(302)
      .end(function (err) {
        if (err) { return done(err); }
        authenticatedSession = testSession;
        return done();
      });
  });

  // if there is this test, test freezes after all test suite finished
  it('/member/profile', (done) => {
    authenticatedSession.get('/member/profile')
      .expect(200)
      .end(done); 
  });
});

Written by Typescript, but executed as javascript with jest

@rjz
Copy link
Owner

rjz commented Apr 16, 2018

Hey @kazkondo, and thanks for reporting this!

It sounds like we may have another async problem, ala #28. Before we cook up a test case, could you confirm:

  1. your installed version of supertest and supertest-session, and also that
  2. the continuation in the last spec is being called as expected?
it('/member/profile', (done) => {
  authenticatedSession.get('/member/profile')
    .expect(200)
    .end((err) => {
      console.log('Yep, definitely broken.');
      done(err);
    }); 
});

@nickfreemandesign
Copy link

nickfreemandesign commented Jun 27, 2018

@rjz I have a similar condition. to answer your clarification, there is no Yep, definitely broken. logged, but the error thrown is TypeError: Cannot read property 'expect' of undefined.

authenticatedSession logs as the testSession as you would expect, in the beforeEach hook.

UDPATE:
my variable testSession was moved to the global scope next to const myApp = require('/myAppPath') as let testSession = session(myApp) and now its 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants