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

Check the type of error instances in tests #1087

Closed
szmarczak opened this issue Feb 24, 2020 · 8 comments · Fixed by #2044
Closed

Check the type of error instances in tests #1087

szmarczak opened this issue Feb 24, 2020 · 8 comments · Fixed by #2044
Labels
enhancement This change will extend Got features good for beginner This issue is easy to fix ✭ help wanted ✭

Comments

@szmarczak
Copy link
Collaborator

No description provided.

@szmarczak szmarczak added enhancement This change will extend Got features ✭ help wanted ✭ labels Feb 24, 2020
@goto1
Copy link
Contributor

goto1 commented Feb 24, 2020

Hi, could you give an example of what you're looking for?

@szmarczak
Copy link
Collaborator Author

t.throws(..., {
    message: '...',
    instanceOf: ErrorClassHere
});

@goto1
Copy link
Contributor

goto1 commented Feb 25, 2020

Got it. I can take a look at this.

@goto1
Copy link
Contributor

goto1 commented Mar 3, 2020

@szmarczak if I change this - https://github.com/sindresorhus/got/blob/master/test/arguments.ts#L18 - to a different type of error, for example URIError, the test should fail when I run npm test, correct? For some reason I am having a hard time failing tests with the npm test command. Any instructions would be appreciated.

Also, I see that some tests have @ts-ignore Error tests added as a comment and some don't - in what cases this should be added as a comment?

Thanks.

@szmarczak
Copy link
Collaborator Author

if I change this - https://github.com/sindresorhus/got/blob/master/test/arguments.ts#L18 - to a different type of error, for example URIError, the test should fail when I run npm test, correct?

That's right.

Also, I see that some tests have @ts-ignore Error tests

The @ts-ignore comment is meant to ignore TypeScript errors. E.g. we use that when it's needed to check whether it rejects when passing a value of not compliant type.

For some reason I am having a hard time failing tests with the npm test command. Any instructions would be appreciated.

Give me a link to your code please, I'll drop you some hints.

@goto1
Copy link
Contributor

goto1 commented Mar 7, 2020

@szmarczak so I change this line of code from instanceOf: TypeError to instanceOf: URIError and I still get the same amount of passed and failed tests:

Here's what I am seeing before changing that line (instanceOf: TypeError):

And here's what I am seeing after (instanceOf: URIError, also ran npx ava reset-cache just in case):

Here's the repo:

This is my first time working with ava so I am going through the docs and trying to get familiar with it. Any tips would be really appreciated.

Thanks.

@szmarczak
Copy link
Collaborator Author

I'll check on this in a few hours.

@szmarczak
Copy link
Collaborator Author

Sorry for late response. Regarding the DNS error, it should be fixed in #1051 I'll get back to you once it's merged.

@szmarczak szmarczak added the good for beginner This issue is easy to fix label Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This change will extend Got features good for beginner This issue is easy to fix ✭ help wanted ✭
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants