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

How to avoid TypeErrors? #372

Open
olalonde opened this issue Apr 6, 2015 · 1 comment
Open

How to avoid TypeErrors? #372

olalonde opened this issue Apr 6, 2015 · 1 comment

Comments

@olalonde
Copy link

olalonde commented Apr 6, 2015

I'm using jasmine-node to test a REST API. My problem is that when a request errors out or something unexpected happens, I always get Javascript TypeErrors because I'm testing properties on object's that are null and the test process never terminates (it just hangs there after encountering the first TypeError error).

For example:

  it('should get resource', function (done) {
    client.get('/some/resouce', function (error, res) {
      expect(error).toBeFalsy();
      expect(res.status).toBe(200);
      done();
    }
  }

The above code will return an error message TypeError: Cannot read property 'status' of undefined if there is an error and jasmine-node just hangs there and never gives me a test report.

I use the following command to run tests: ./node_modules/.bin/jasmine-node test/ --verbose --autotest --captureExceptions --color --watch ./server

Is there any way to avoid those errors?

@olalonde
Copy link
Author

olalonde commented Apr 6, 2015

Oh, I just realised I could do:

  it('should get resource', function (done) {
    client.get('/some/resouce', function (error, res) {
      if (error) return done(error);
      expect(res.status).toBe(200);
      done();
    }
  }

This seems to solve my problem for now!

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

1 participant