@case-contract-testing/case
Version:
Next-generation contract testing suite
50 lines (49 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.rawEquality = void 0;
const entities_1 = require("../../../../entities");
const rawEquality = (a, b) => {
if (typeof a === 'function' ||
typeof a === 'bigint' ||
typeof a === 'symbol') {
throw new entities_1.CaseConfigurationError(`It looks like an object of type '${typeof a}' was attempted to be serialised in the contract. This is unsupported`);
}
if (typeof b === 'function' ||
typeof b === 'bigint' ||
typeof b === 'symbol') {
throw new entities_1.CaseConfigurationError(`It looks like an object of type '${typeof b}' was attempted to be serialised in the contract. This is unsupported`);
}
if (typeof a !== typeof b)
return false;
if (typeof a === 'string')
return a === b;
if (typeof a === 'number')
return a === b || (Number.isNaN(a) && Number.isNaN(b));
if (typeof a === 'boolean')
return a === b;
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length)
return false;
return a
.map((item, index) => (0, exports.rawEquality)(item, b[index]))
.reduce((acc, curr) => acc && curr, true);
}
if (typeof a === 'object' &&
a === Object(a) &&
!Array.isArray(a) &&
a != null &&
typeof b === 'object' &&
b === Object(b) &&
!Array.isArray(b) &&
b != null) {
const aEntries = Object.entries(a);
const bEntries = Object.entries(b);
if (aEntries.length !== bEntries.length)
return false;
return aEntries
.map(([key, value]) => (0, exports.rawEquality)(value, b[key]))
.reduce((acc, curr) => acc && curr, true);
}
return false;
};
exports.rawEquality = rawEquality;