software-tools-books / js4ds

JavaScript for Data Science
https://third-bit.com/js4ds/
Other
187 stars 32 forks source link

Testing the Server - need .get before .expect #217

Open asbates opened 4 years ago

asbates commented 4 years ago

For the 404 test in the 'Testing the Server' section, I think the .get needs to be called before .expect.

The test is

  it('should 404 for other pages', (done) => {
    request(server)
      .expect(404) // expect first
      .get('/other')
      .end((err, res) => {
        assert(res.text.includes('ERROR'), 'Has expected error message')
        done()
      })
  })

When I runs the tests with this, I get TypeError: request(...).expect is not a function.

I think it should be

  it('should 404 for other pages', (done) => {
    request(server)
      .get('/other') // get first
      .expect(404)
     // ...
      })
  })

where the get request is made before we can check the result is as expected. Doing this results in a passing test for me.

Happy to submit a PR if you all agree with my assessment.