Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with assertions when using thenables #14

Merged
merged 2 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hapi-test",
"version": "7.0.0",
"version": "7.0.1",
"description": "Test hapi plugins with chaining method calls and assertions",
"main": "index.js",
"repository": {
Expand Down
5 changes: 4 additions & 1 deletion src/hapiTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ class HapiTest {
}

then(callbackSuccess, callbackError) {
return this.end().then(callbackSuccess, errors => callbackError && callbackError(getFirstError(errors)));
return this.end().then(callbackSuccess, errors => callbackError
? callbackError(getFirstError(errors))
: Promise.reject(getFirstError(errors))
);
}

catch(callbackError) {
Expand Down
14 changes: 14 additions & 0 deletions test/hapiTestSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ describe('hapi-test', function () {
.assert(200);
});

it('should reject when using assertions with thenables', async function () {
try {
await hapiTest({
plugins: [plugin]
})
.get('/one')
.assert(1000)
.then(() => {});
throw new Error('Promise was resolved when a rejection was expected');
} catch (err) {
assert.equal(err.message, 'the status code is: 200 but should be: 1000');
}
});

it('should pass assertion errors to the end method', async function () {
try {
await hapiTest({ plugins: [plugin] })
Expand Down