mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
I accidentally removed this in 41ac86129b9b45216708c307645a0fc47eecf8bf, resulting in much breakage.
72 lines
2.1 KiB
JavaScript
72 lines
2.1 KiB
JavaScript
const _ = require('lodash');
|
|
const { addMatchers } = require('add-matchers');
|
|
|
|
// Adds matchers from https://github.com/JamieMason/Jasmine-Matchers.
|
|
require('jasmine-expect');
|
|
|
|
addMatchers({
|
|
toBeError(value) {
|
|
return value instanceof Error;
|
|
},
|
|
toBeErrorOfType(other, value) {
|
|
return value instanceof Error && value.name === other;
|
|
},
|
|
toBeInstanceOf(other, value) {
|
|
let otherName;
|
|
let valueName;
|
|
|
|
if (typeof value !== 'object') {
|
|
throw new TypeError(`Expected object value, got ${typeof value}`);
|
|
}
|
|
|
|
valueName = value.constructor.name;
|
|
|
|
if (typeof other === 'string') {
|
|
// Class name.
|
|
otherName = other;
|
|
} else if (typeof other === 'function') {
|
|
// Class constructor.
|
|
otherName = other.name;
|
|
} else {
|
|
otherName = other.constructor.name;
|
|
}
|
|
|
|
return valueName === otherName;
|
|
},
|
|
toHaveOwnProperty(other, value) {
|
|
return Object.hasOwn(value, other);
|
|
},
|
|
// The objects in `value` must have all of the keys and values from the corresponding objects in
|
|
// `other`. The object in `value` can have additional properties as well. For example, if
|
|
// `other[0]` is `{ a: 1 }`, and `value[0]` is `{ a: 1, b: 2 }`, then the objects match.
|
|
toMatchArrayOfObjects(other, value) {
|
|
let isMatch = true;
|
|
|
|
if (!Array.isArray(value)) {
|
|
throw new TypeError(`Expected array value, got ${typeof value}`);
|
|
}
|
|
if (!Array.isArray(other)) {
|
|
throw new TypeError(`Expected array value as expected value, got ${typeof other}`);
|
|
}
|
|
|
|
if (other.length !== value.length) {
|
|
isMatch = false;
|
|
} else {
|
|
for (let i = 0, l = value.length; i < l; i++) {
|
|
if (!_.isMatch(value[i], other[i])) {
|
|
isMatch = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return isMatch;
|
|
},
|
|
// The `value` object must have all of the keys and values from the `other` object. The `value`
|
|
// object can have additional properties as well. For example, if `other` is `{ a: 1 }`, and
|
|
// `value` is `{ a: 1, b: 2 }`, then the objects match.
|
|
toMatchObject(other, value) {
|
|
return _.isMatch(value, other);
|
|
},
|
|
});
|