Chai: Object have a property or an empty object assertion.

Created on 15 Nov 2016  路  2Comments  路  Source: chaijs/chai

Hello!

My method returns either an object with some (predetermined) property or an empty object.

How I can make such assertion in BDD style (exept using ".satisfy" :-) )?

I need something like this:

expect(foo).to.have.all.key('bar').or.to.be.deep.equal({})
question

Most helpful comment

@RidgeA I recommend against writing tests that assert on multiple outcomes. Please check out my comment in this thread.

In your example, I recommend writing two separate tests. The first test sets up the specific conditions that leads to the method returning an object with the bar property, and then asserts that the object is indeed returned under those conditions. The second test sets up the specific conditions that leads to the method returning an empty object, and then asserts that an empty object is indeed returned under those conditions.

All 2 comments

@RidgeA I recommend against writing tests that assert on multiple outcomes. Please check out my comment in this thread.

In your example, I recommend writing two separate tests. The first test sets up the specific conditions that leads to the method returning an object with the bar property, and then asserts that the object is indeed returned under those conditions. The second test sets up the specific conditions that leads to the method returning an empty object, and then asserts that an empty object is indeed returned under those conditions.

Okey, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

endymion00 picture endymion00  路  3Comments

zzzgit picture zzzgit  路  3Comments

meeber picture meeber  路  4Comments

AnAppAMonth picture AnAppAMonth  路  3Comments

liborbus picture liborbus  路  4Comments