Asserts on "undefined" always fail due to JSON.stringify(window) #8

Open
niallsmart opened this Issue Jun 14, 2011 · 1 comment

Comments

Projects
None yet
1 participant
@niallsmart

Either of the following assertions throws a TypeError due to SpecIt calling JSON.stringify(window):

assert(undefined).shouldNot(be);
assert(undefined).should(eql, undefined);

The problem originates in objectToSpecIt() which passes expectation as the first argument to Function.apply – however when expectation is undefined, then this is the global object in the called function (as expected: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply). In a browser the global context is window, so later on SpecIt calls JSON.stringify(actual) when actual === window.

I've implemented a kludgy workaround, which specially maps undefined to a UndefinedWrapper singleton.

@niallsmart

This comment has been minimized.

Show comment Hide comment
@niallsmart

niallsmart Jun 14, 2011

Also noticed this affects asserts on null; used a wrapper class instead of a singleton in final fix above.

Also noticed this affects asserts on null; used a wrapper class instead of a singleton in final fix above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment