Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function deepEqual(actual, expected) {
const ret = concordance.compare(actual, expected)
if (!ret.pass) {
const a = ret.actual || concordance.describe(actual)
const e = ret.expected || concordance.describe(expected)
return false
}
return true
}
this.is = withSkip((actual, expected, message) => {
if (!checkMessage('is', message)) {
return;
}
if (Object.is(actual, expected)) {
pass();
} else {
const result = concordance.compare(actual, expected, concordanceOptions);
const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions);
const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions);
if (result.pass) {
fail(new AssertionError({
assertion: 'is',
message,
raw: {actual, expected},
values: [formatDescriptorWithLabel('Values are deeply equal to each other, but they are not the same:', actualDescriptor)]
}));
} else {
fail(new AssertionError({
assertion: 'is',
message,
raw: {actual, expected},
values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)]
assertEquals(expected, actual, message = '') {
if (!concordance.compare(expected, actual).pass) {
throw new AssertionError({message : `${message}\n${concordance.diff(expected, actual)}`});
}
}
assertNotEquals(expected, actual, message = '') {
if (concordance.compare(expected, actual).pass) {
let defaultMessage = `Expected value is equal to actual value`;
throw new AssertionError({message: message || defaultMessage});
}
}
deepEqual(actual, expected, message) {
const result = concordance.compare(actual, expected, concordanceOptions);
if (result.pass) {
pass(this);
} else {
const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions);
const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions);
fail(this, new AssertionError({
assertion: 'deepEqual',
message,
raw: {actual, expected},
values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)]
}));
}
},
notDeepEqual(actual, expected, message) {
const result = concordance.compare(actual, expected, concordanceOptions);
if (result.pass) {
const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions);
fail(this, new AssertionError({
assertion: 'notDeepEqual',
message,
raw: {actual, expected},
values: [formatDescriptorWithLabel('Value is deeply equal:', actualDescriptor)]
}));
} else {
pass(this);
}
},
module.exports = function diffValues(actual, expected) {
const result = concordance.compare(actual, expected, concordanceOptions)
if (result.pass) {
return null
}
const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions)
const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions)
return formatDescriptorDiff(actualDescriptor, expectedDescriptor)
}