doctestjs icon indicating copy to clipboard operation
doctestjs copied to clipboard

Conditional output expectations

Open ianb opened this issue 13 years ago • 3 comments

Some output differs based on environment. For instance:

x = null;
x.y;

That says something like TypeError: x is null in Firefox, and TypeError: Cannot read property 'y' of null in Chrome. Neither one is "right" per se. You could just use ... to ignore the content entirely, but that's not super.

Instead, something like:

/* == when userAgent('Chrome')
=> Error: TypeError: Cannot read property 'y' of null
== when userAgent('Firefox')
=> Error: TypeError: x is null
*/

The code after when would be an expression, with some helpers available like a function for simple user-agent selection.

ianb avatar Sep 26 '12 02:09 ianb

Another variant would be to allow a set of different results:

// => Error: TypeError: Cannot read property 'y' of null {or} Error: TypeError: x is null

boxed avatar Mar 30 '13 20:03 boxed

I agree a simple "or" is probably good enough, instead of conditional expressions. But maybe like:

// => Error: TypeError Cannot ...
// OR => Error: TypeError: x is null

ianb avatar Apr 05 '13 17:04 ianb

Ah, yea, that's much cleaner :P

boxed avatar Apr 06 '13 15:04 boxed