mirror of
https://github.com/hanzoai/Detox.git
synced 2026-09-24 16:55:12 +00:00
21 lines
527 B
JavaScript
21 lines
527 B
JavaScript
async function expectToThrow(testBlock, withMessage) {
|
|
|
|
try {
|
|
await testBlock();
|
|
} catch (e) {
|
|
if (withMessage && !e.message.includes(withMessage)) {
|
|
throw new Error(`Caught an expected error but message was different:\nExpected: ${withMessage}\nReceived: ${e.message}`)
|
|
}
|
|
|
|
const [firstLine] = e.message.split('\n', 1);
|
|
console.log('Caught an expected error:', firstLine);
|
|
return e;
|
|
}
|
|
|
|
throw new Error('Expected an error but nothing was thrown');
|
|
}
|
|
|
|
module.exports = {
|
|
expectToThrow,
|
|
};
|