Merge branch 'enelson/toBeInstanceOf' of https://github.com/elliot-nelson/jasmine into elliot-nelson-enelson/toBeInstanceOf

- Merges #1697 from @elliot-nelson
This commit is contained in:
Gregg Van Hove
2019-05-16 17:31:13 -07:00
4 changed files with 327 additions and 0 deletions

View File

@@ -109,6 +109,7 @@ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
'toBe',
'toBeCloseTo',
'toBeDefined',
'toBeInstanceOf',
'toBeFalse',
'toBeFalsy',
'toBeGreaterThan',
@@ -4301,6 +4302,52 @@ getJasmineRequireObj().toBeGreaterThanOrEqual = function() {
return toBeGreaterThanOrEqual;
};
getJasmineRequireObj().toBeInstanceOf = function(j$) {
var usageError = j$.formatErrorMsg('<toBeInstanceOf>', 'expect(value).toBeInstanceOf(<ConstructorFunction>)');
/**
* {@link expect} the actual to be an instance of the expected class
* @function
* @name matchers#toBeInstanceOf
* @param {Object} expected - The class or constructor function to check for
* @example
* expect('foo').toBeInstanceOf(String);
* expect(3).toBeInstanceOf(Number);
* expect(new Error()).toBeInstanceOf(Error);
*/
function toBeInstanceOf(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
var actualType = actual && actual.constructor ? j$.fnNameFor(actual.constructor) : j$.pp(actual),
expectedType = expected ? j$.fnNameFor(expected) : j$.pp(expected),
expectedMatcher,
pass;
try {
expectedMatcher = new j$.Any(expected);
pass = expectedMatcher.asymmetricMatch(actual);
} catch (error) {
throw new Error(usageError('Expected value is not a constructor function'));
}
if (pass) {
return {
pass: true,
message: 'Expected instance of ' + actualType + ' not to be an instance of ' + expectedType
};
} else {
return {
pass: false,
message: 'Expected instance of ' + actualType + ' to be an instance of ' + expectedType
};
}
}
};
}
return toBeInstanceOf;
};
getJasmineRequireObj().toBeLessThan = function() {
/**
* {@link expect} the actual value to be less than the expected value.