Closed buschtoens closed 11 years ago
I am looking for something like:
e.g. response.should.have.status(201).or(409);
So .or
should be a function that, when called performs the last check again with the new supplied argument, or performs the appended checks. Nice sugar.
myObj
.should.be.a("string")
.or("number"); // redo type check
myObj
.should.be.a("string")
.or.be.an.instanceOf(Array); // do the appended check
myObj
.should.be.a("string")
.or("number") // redo type check
.be.an.instanceOf(Array); // do the appended check
or seems a bit odd for a test that should be deterministic
On first glance yes. But think about APIs that may return a value or null
, if no data was found.
you should have a separate test case for those scenarios
Ah yes, that's true.
thoughts on re-opening this? I have a case where I think it would be useful. My application needs to retrieve data, and that data can be either XML or JSON, so being able to do
response.should.have
.header("content-type", "application/json")
.or("content-type", "application/xml");
I can set up a PR if we agree it would be a beneficial addition
well, it is still unclear - even in your case response either json or xml, and it depends from actual request - so it is separate tests. From technical point it is very unclear how .or should work, because as soon .header executed and failed - it will throw error and .or will not be executed.
@btd but I don't know what the request is going to return. the modules I wrote to parse the data (not being tested here) accept XML or JSON, so all I need to do in the test is ensure that they return the proper data.
It does seem a bit complicated on the technical side. I haven't delved too much into the codebase yet, but it may be worth looking at how q.js handles .catch
.
Your tests should know which of XML or JSON is supposed to come back given an input. If that's nondeterministic, I'd wager you're going to have larger issues :)
The issue is that data providers in my particular case can give XML or JSON, and dealing with that data is a job for a separate adapter behavior that I didn't want to test there. I suppose I can add a property tagging it as an XML or JSON provider.
The concern I'd have with a test checking xml || json
is that the controller could report a Content-Type
that doesn't match what your provider generated. I'd totally build two tests and stub or specify the format it's returning in each.
good point. thanks! :)
Would be quite useful.