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({})
@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!
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
barproperty, 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.