Fixed toHaveSize matcher on IE 10 & 11

This commit is contained in:
Steve Gravrock
2020-04-12 13:43:44 -07:00
parent 78c3a007ad
commit 8991b1bba3
7 changed files with 67 additions and 6 deletions

View File

@@ -148,6 +148,24 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
);
};
j$.isWeakMap = function(obj) {
return (
obj !== null &&
typeof obj !== 'undefined' &&
typeof jasmineGlobal.WeakMap !== 'undefined' &&
obj.constructor === jasmineGlobal.WeakMap
);
};
j$.isDataView = function(obj) {
return (
obj !== null &&
typeof obj !== 'undefined' &&
typeof jasmineGlobal.DataView !== 'undefined' &&
obj.constructor === jasmineGlobal.DataView
);
};
j$.isPromise = function(obj) {
return (
typeof jasmineGlobal.Promise !== 'undefined' &&

View File

@@ -16,11 +16,11 @@ getJasmineRequireObj().toHaveSize = function(j$) {
pass: false
};
if (j$.isA_('WeakSet', actual) || j$.isA_('WeakMap', actual) || j$.isA_('DataView', actual)) {
if (j$.isA_('WeakSet', actual) || j$.isWeakMap(actual) || j$.isDataView(actual)) {
throw new Error('Cannot get size of ' + actual + '.');
}
if (actual instanceof Set || actual instanceof Map) {
if (j$.isSet(actual) || j$.isMap(actual)) {
result.pass = actual.size === expected;
} else if (isLength(actual.length)) {
result.pass = actual.length === expected;