-
Notifications
You must be signed in to change notification settings - Fork 283
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
test: refactor try-catch based negative scenarios with Jest matchers #3455
Labels
good-first-issue
Good for newcomers
good-first-issue-100-introductory
good-first-issue-200-intermediate
Hacktoberfest
Hacktoberfest participants are welcome to take a stab at issues marked with this label.
P4
Priority 4: Low
Tests
Anything related to tests be that automatic or manual, integration or unit, etc.
Comments
petermetz
added
good-first-issue
Good for newcomers
Hacktoberfest
Hacktoberfest participants are welcome to take a stab at issues marked with this label.
good-first-issue-100-introductory
good-first-issue-200-intermediate
Tests
Anything related to tests be that automatic or manual, integration or unit, etc.
P4
Priority 4: Low
labels
Aug 3, 2024
petermetz
referenced
this issue
in petermetz/cacti
Aug 3, 2024
1. The Jest test execution was turned off for the AWS SM keychain plugin for some reason so this PR enables it back and while at it 2. I also refactored one of the test cases to have less linter warnings about us casting to `any`. 3. And on top of that I also migrated one of the test cases to Jest from TAP/tape so that we are making some progress with the test coverage at the same time. One more notable thing is that I refactored the negative test assertions while migrating to Jest so the test case now uses Jest native assertions to check what exactly the error message returned by the API call for deleting a non-existent item looks like. This is an example of the refactoring that this issue is about: https://github.com/hyperledger/cacti/issues/3455 Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
I would like to work on this Issue. |
@Deepakchowdavarapu OK, I opened an issue with the limited scope here: https://github.com/hyperledger/cacti/issues/3457 |
petermetz
referenced
this issue
in petermetz/cacti
Aug 8, 2024
1. The Jest test execution was turned off for the AWS SM keychain plugin for some reason so this PR enables it back and while at it 2. I also refactored one of the test cases to have less linter warnings about us casting to `any`. 3. And on top of that I also migrated one of the test cases to Jest from TAP/tape so that we are making some progress with the test coverage at the same time. One more notable thing is that I refactored the negative test assertions while migrating to Jest so the test case now uses Jest native assertions to check what exactly the error message returned by the API call for deleting a non-existent item looks like. This is an example of the refactoring that this issue is about: https://github.com/hyperledger/cacti/issues/3455 Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
petermetz
referenced
this issue
Aug 9, 2024
1. The Jest test execution was turned off for the AWS SM keychain plugin for some reason so this PR enables it back and while at it 2. I also refactored one of the test cases to have less linter warnings about us casting to `any`. 3. And on top of that I also migrated one of the test cases to Jest from TAP/tape so that we are making some progress with the test coverage at the same time. One more notable thing is that I refactored the negative test assertions while migrating to Jest so the test case now uses Jest native assertions to check what exactly the error message returned by the API call for deleting a non-existent item looks like. This is an example of the refactoring that this issue is about: https://github.com/hyperledger/cacti/issues/3455 Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
This was referenced Aug 11, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
good-first-issue
Good for newcomers
good-first-issue-100-introductory
good-first-issue-200-intermediate
Hacktoberfest
Hacktoberfest participants are welcome to take a stab at issues marked with this label.
P4
Priority 4: Low
Tests
Anything related to tests be that automatic or manual, integration or unit, etc.
Description
Jest has very handy assertions (jest-extended to be more specific) which make it possible to assert the contents of an error response coming from the API.
These assertion APIs have easier to read reporting and are less confusing then the manually triggered test failures we are forced to do in the try-catch block's try leg if the operation unexpectedly succeeds with the negative scenario.
Instead of relying on clunky try-catch blocks and exception type casting we should use the native support Jest has.
As an example this is how it should be refactored, see the before and after. The two test assertions are equivalent but one is more concise, reads more like English prose and points out exactly what was not matching the assertions if there is a failure.
before
after
Acceptance Criteria
The text was updated successfully, but these errors were encountered: