Skip to content

Commit

Permalink
Experiment: relax specified order in which mirage errors should be th…
Browse files Browse the repository at this point in the history
…rown
  • Loading branch information
gilest committed Jun 1, 2021
1 parent 6ae3438 commit ebf5533
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tests/integration/components/mirage-handler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,21 @@ module('Integration | Component | mirage-handler', function (hooks) {
};
for (let [type, file] of Object.entries(SCENARIOS)) {
test(`upload handler throws if invalid ${type} is provided`, async function (assert) {
let errorCount = 0;
const errorsThrown = [];
setupOnerror((error) => {
// expect two errors:
// 1. error thrown by our upload handler
// 2. error thrown by 500 response that includes the first error as body
if (errorCount === 0) {
// * error thrown by our upload handler
// * error thrown by 500 response that includes the first error as body
if (error.message) {
// error thrown by our mirage handler
assert.step('error thrown');
errorsThrown.push('handler error');
assert.ok(error.message.includes(`invalid ${type}`));
} else {
} else if (error.status) {
// error from 500 response
assert.step('500 response');
errorsThrown.push('500 response');
assert.equal(error.status, 500);
assert.ok(error.body.error.includes(`invalid ${type}`));
}

errorCount++;
});

this.server.post(
Expand All @@ -117,7 +115,8 @@ module('Integration | Component | mirage-handler', function (hooks) {

await selectFiles('input', file);

assert.verifySteps(['error thrown', '500 response']);
assert.ok(errorsThrown.includes('handler error'), 'handler error thrown');
assert.ok(errorsThrown.includes('500 response'), '500 response thrown');
});
}
});

0 comments on commit ebf5533

Please sign in to comment.