I'm using buster.js and the "expect" assertions. I want the assertion to succeed in at least one of:
expect(req.body.data._id).toBe('foo bar baz');
or
expect(req.body.data.id).toBe('foo bar baz');
How can I do it?
I'm using buster.js and the "expect" assertions. I want the assertion to succeed in at least one of:
expect(req.body.data._id).toBe('foo bar baz');
or
expect(req.body.data.id).toBe('foo bar baz');
How can I do it?
Having a look at the relevant documentation it looks like you want
expect([req.body.data._id, req.body.data.id]).toContain('foo bar baz');
While the answer from @glenn jackman is good enough, to get more semantic related reading, you could use Array.prototype.some function with some isEqual
analog. Example:
var isEqual = function(first) { return function(second) { return first === second; }; }
[1,2,3].some(isEqual(2); // true
expect([1,2,3].some(isEqual(2))).toBeTrue(); // passed
expect([1,2,3].some(isEqual(4))).toBeTrue(); // failed
Or you could walk further on this way:
var someOf = function(array) { return array.some.bind(array); };
expect(someOf([1,2,3])(isEqual(1))).toBeTrue(); // passed
Get rid of brackets:
var someOf = function(array) {
return { isEqual: function(x) { return array.some(isEqual(x)); } };
}
expect(someOf([1,2,3]).isEqual(4)).toBeTrue();
I believe you can do more with creating custom 'expectations' with buster.referee.add.
expect(req.body.data._id || req.body.data.id).toBe('foo bar baz');