Explicit type cast when asserting, inspecting, and diffing
So that the base types can be utilized better.
Something like:
expect(expect.cast('object', new Error('blah')), 'to equal', {message: 'blah'});
function MyThing() {}
expect.addType({
name: 'myThing',
base: 'object',
identify: function (obj) {
return obj instanceof MyThing;
},
inspect: function (output, myThing, inspect, depth) {
return output.text('MyThing: ').append(inspect(expect.cast('object', myThing)));
},
diff: function (output, actual, expected, diff) {
var result = diff(expect.cast('object', actual), expect.cast('object', expected));
result.diff.text("... and that's that");
return result;
}
});
Would be nice if it could accept a type name as well as a type object so that expect.cast(this.baseType, ...) could also work.
Unfortunately this is not going to work like described above. Getting the cast type to "stick" when an assertion delegates to another assertion won't work without some sort of opt-in from each assertion, and that's a no-go. The use case is still there, but I'll work around it for now. Back to the drawing board.
Landed the start of a spike on the cast branch.
Needs special casing in it, equal, inspect, and diff on wrappedExpect when casts are active.