Skip to content

fix: Unhandled promise rejection in tests #95

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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 8 additions & 5 deletions test/bindings/http/unmarshaller_0_3_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
expect(err.message).to.equal("structured+type not allowed"));
});

it("Throw error when the event does not follow the spec 0.3", () => {
it("Throw error when the event does not follow the spec 0.3", async() => {
// setup
const payload =
new v03.CloudEvent(v03.Spec)
Expand All @@ -108,10 +108,13 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
const un = new Unmarshaller();

// act and assert
un.unmarshall(payload, headers)
.then(() => { throw new Error("failed"); })
.catch((err) =>
expect(err.message).to.equal("invalid payload"));
try {
await un.unmarshall(payload, headers);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@helio-frota you should fail the test after this line. The expectation is that the unmarshalling should throw if the incoming message does not conform to spec. As the test is now, that isn't happening. We never enter the catch block below. You can change that .to.equal() call to be .to.equal('tacos') and the test still passes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOps you right! I was only focused on solve the unhandled promise exception.
Thanks for the review, commit updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still not good btw..
I'm trying to understand what is happening...

const spec = new v03.Spec();
spec.check(payload);
} catch (err) {
expect(err.message).to.equal("invalid payload");
}
});

it("Should accept event that follow the spec 0.3", () => {
Expand Down