Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const printCloseTo = (
receivedDiff: number,
expectedDiff: number,
precision: number,
isNot: boolean,
): string => {
const receivedDiffString = stringify(receivedDiff);
const expectedDiffString = receivedDiffString.includes('e')
? // toExponential arg is number of digits after the decimal point.
expectedDiff.toExponential(0)
: 0 <= precision && precision < 20
? // toFixed arg is number of digits after the decimal point.
// It may be a value between 0 and 20 inclusive.
// Implementations may optionally support a larger range of values.
expectedDiff.toFixed(precision + 1)
: stringify(expectedDiff);
return (
`Expected precision: ${isNot ? ' ' : ''} ${stringify(precision)}\n` +
`Expected difference: ${isNot ? 'not ' : ''}< ${EXPECTED_COLOR(
expectedDiffString,
)}\n` +
`Received difference: ${isNot ? ' ' : ''} ${RECEIVED_COLOR(
receivedDiffString,
)}`
);
};
].forEach(([timestamp, dateTimeString]) => {
it(`serializes Unix timestamp ${stringify(timestamp)} into date-time-string ${dateTimeString}`, () => {
expect(serializeUnixTimestamp(timestamp)).toEqual(dateTimeString)
})
});
].forEach(([date, dateString]) => {
it(`serializes ${stringify(date)} into date-string ${dateString}`, () => {
expect(serializeDate(date)).toEqual(dateString)
})
});
].forEach(([dateString, date]) => {
it(`parses date ${stringify(dateString)} into Date ${stringify(date)}`, () => {
expect(parseDate(dateString)).toEqual(date)
})
});
function getAttributeComment(name, value) {
return value === undefined
? `element.hasAttribute(${stringify(name)})`
: `element.getAttribute(${stringify(name)}) === ${stringify(value)}`
}
function display(value) {
return typeof value === 'string' ? value : stringify(value)
}
return `${key}={null}`;
}
if (typeof value === 'string') {
return `${key}="${value}"`;
}
if (typeof value === 'boolean' && value) {
return value ? `${key}` : `${key}={false}`;
}
if (value instanceof Array) {
return `${key}={${stringify(value, verbosity + 1)}}`;
}
return `${key}={${stringify(value, verbosity)}}`;
}
message: () => {
return [
matcherHint(
`${this.isNot ? '.not' : ''}.toContainElement`,
'element',
'element',
),
'',
receivedColor(`${stringify(container.cloneNode(false))} ${
this.isNot ? 'contains:' : 'does not contain:'
} ${stringify(element ? element.cloneNode(false) : element)}
`),
].join('\n')
},
}
function printAttribute(name, value) {
return value === undefined ? name : `${name}=${stringify(value)}`
}