mercredi 30 septembre 2015

Node Jasmine 2.0 and multiple conditions

Jasmine has this funky methodology of not halting at a first failure within a test. This is fine in general, but it doesn't come without issues. I'm wondering what the best practice is for a scenario such as this:

it('should process async results nicely', function (done) {
    this.getJSON('something', function(response) {
        expect(response.status).toEqual('ok');
        expect(response.data).toBeDefined();
        expect(response.data.length).toEqual(5);
        done();
    }
}

The problem here is that this will crash the whole test suite if response.data is undefined. Then again, writing conditionals within a test case is generally frowned upon. Do I have any other choice for this scenario? Given the async nature of most of the tests, this is a very common issue.

Aucun commentaire:

Enregistrer un commentaire