-
Notifications
You must be signed in to change notification settings - Fork 18
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: use assert.rejects and drop chai #194
Conversation
}); | ||
it('Forwards GitHub error if createTree fails', async () => { | ||
// setup | ||
const createTreeErrorMsg = 'Error committing'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok this requires an explanation :) With try/catch test pattern here, the intent was to ensure the code throws an error, and then check the error message. That only works if you put an assert.fail
after the code that you expect to throw. Turns out ... these tests never worked as intended. The handleTree
method here and below never actually threw, so when I converted them to assert.rejects
, the tests started failing. Since they never worked as intended, I just went ahead and removed them. We can come back around to improve coverage.
Codecov Report
@@ Coverage Diff @@
## master #194 +/- ##
==========================================
+ Coverage 87.88% 88.04% +0.16%
==========================================
Files 24 24
Lines 2303 2301 -2
Branches 152 168 +16
==========================================
+ Hits 2024 2026 +2
+ Misses 279 275 -4
Continue to review full report at Codecov.
|
}); | ||
it('fails when there is no env variable', async () => { | ||
try { | ||
sandbox.stub(process.env, 'ACCESS_TOKEN').value(undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another fun fact! This code was throwing when it tried to create the stub, because ACCESS_TOKEN
didn't exist as a property. This test was bunk.
// tests | ||
const changes = parseTextFiles(userFilesMap); | ||
expect(changes).to.deep.equal(parsedMap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now fully distrust the deep equal implementation in Chai. The returned object was actually a set with class instances, not naked objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering which refactor you were tweeting about 😆
Apologies for the size of the review. This PR does a few things in pursuit of test cleanup:
chai
, and uses the built inassert
moduleassert.throws
andassert.rejects
instead of try/catch gymnasticstslint
ignore tags