Skip to content

How can I test the connection refused case? #62

Answered by ASaiAnudeep
LonelyGriffin asked this question in Q&A
Discussion options

You must be logged in to vote
Welcome to PactumJS Discussions & Thanks a lot for using this library.

This is an interesting use case. PactumJS doesn't have a native method to support error expectations. I too agree that we should have one.

As you mentioned having a method like expectConnectionRefused would solve this issue but it is explicit. We will discuss further and consider adding this method.

Instead, I will add a method something like expectError that would be generic for broader use cases.

// expect any error
await pactum.spec().get(healthUrl).expectError();

// expect ECONNREFUSED error
await pactum.spec().get(healthUrl).expectError('ECONNREFUSED');

// expect error object
await pactum.spec().get(healthUrl).e…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ASaiAnudeep
Comment options

Answer selected by ASaiAnudeep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants