Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let { expected, msg } = res
const showDiff = expected !== undefined
if (showDiff) {
// if the error starts with "expected" and we can show a diff,
// then prefix the error message with `\w+: expected` (lower-case e)
// and mocha will drop everything after the :
// https://github.com/mochajs/mocha/blob/c0f9be244bff479e948f59d1bdb825a45c2cb40c/lib/reporters/base.js#L208-L209
if (msg.match(/^expected /i)) {
msg = `expect-to assertion failure: expected ${msg.slice(9)}`
}
}
throw new AssertionError(msg, { showDiff, actual, expected })
}
}
export const createWaitForElement = (selector, maxTime = 2000, interval = 10) => rootComponent => {
// Check correct usage
if (!selector) {
return Promise.reject(new AssertionError(`No selector specified in ${DISPLAY_NAME}.`));
}
if (!rootComponent) {
return Promise.reject(new AssertionError(`No root component specified in ${DISPLAY_NAME}.`));
}
if (!rootComponent.length) {
return Promise.reject(new AssertionError(`Specified root component in ${DISPLAY_NAME} not found.`));
}
// Race component search against maxTime
return new Promise((resolve, reject) => {
let remainingTime = maxTime;
const intervalId = setInterval(() => {
if (remainingTime < 0) {
clearInterval(intervalId);
return reject(new AssertionError(`Expected to find ${selector} within ${maxTime}ms, but it was never found.`))
}
const targetComponent = rootComponent.update().find(selector);
if (targetComponent.length) {
.then(() =>
reject(new AssertionError('Plugin should not have copied jQuery'))
)
.then(() =>
reject(new AssertionError('Plugin should not have injected jQuery'))
)
.then(() =>
reject(new AssertionError('Plugin should not have excluded jQuery'))
)
.then(() =>
reject(
new AssertionError(
'index.html should not have had the assets inserted into the HTML'
)
)
)