unexpected icon indicating copy to clipboard operation
unexpected copied to clipboard

Explicit type cast when asserting, inspecting, and diffing

Open papandreou opened this issue 11 years ago • 3 comments

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.

papandreou avatar Sep 01 '14 08:09 papandreou

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.

papandreou avatar Sep 06 '14 07:09 papandreou

Landed the start of a spike on the cast branch.

papandreou avatar May 18 '15 13:05 papandreou

Needs special casing in it, equal, inspect, and diff on wrappedExpect when casts are active.

papandreou avatar May 18 '15 13:05 papandreou