ladjs/supertest

typeerror on callback

vividsystem opened this issue · 1 comments

So I am having a very random error on the response callbacks my tests look something like this:

  it('POST / -> successful', () => {
    let username = (Date.now()).toString(32);
    let email = `${(Date.now()).toString(32)}@test.dev`
    let password = `${(Date.now()).toString(32)}@123`
    return request(userRouter)
      .post('/')
      .send({ name: username, email: email, password: password })
      .expect(201)
      .expect('Content-Type', /json/)
      .then((response) => { // error happens after breakpoint here
        expect(response.body).toEqual(
          expect.objectContaining({
            id: expect.any(Number),
            createdAt: expect.stringMatching(timeRegex),
            name: expect.stringMatching(username),
            email: expect.stringMatching(email)
          })
        );
        testUsers.push(response.body as User)
      }, (response) => {
        console.log(response)
      });
  });

After some debugging using Visual Studio Code's Debug features. I figured the error happened after the breakpoint but I couldn't find out more since

I am getting the following error:
TypeError: Cannot read property 'apply' of undefined