-
Notifications
You must be signed in to change notification settings - Fork 7
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
chore(tests): add unit tests to contract functions #18
Conversation
8f830a7
to
8637271
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #18 +/- ##
==========================================
+ Coverage 7.90% 81.25% +73.34%
==========================================
Files 11 11
Lines 177 176 -1
Branches 42 41 -1
==========================================
+ Hits 14 143 +129
+ Misses 144 33 -111
+ Partials 19 0 -19 ☔ View full report in Codecov by Sentry. |
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.
small comments r.e. test setup - but looking good!
src/actions/write/evolve.test.ts
Outdated
}); | ||
|
||
it.each(['hacker'])( |
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.
add a number, boolean, object, etc
}, | ||
})) as AntContractWriteResult; | ||
|
||
expect(result.state).not.toContain(target); |
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.
broad check, refine to controllers array
import { setController } from './setController'; | ||
|
||
describe('setController', () => { | ||
let state = { ...baselineAntState }; |
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.
you can just spread baselineAntState
in your tests rather than do this and the beforeEach
let state = { ...baselineAntState }; | ||
|
||
beforeEach(() => { | ||
state = { ...baselineAntState }; | ||
}); |
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 would create a function and use it when you want the ANT state. you can then remove these lines.
e.g.
export functon generateAntBaseState = (params) => {
return {
....baselineAntState
}
}
and instead of
const _state = { ...state, controllers: [target] };
use the function
const initState = { ...generateBaselineAntState, controllers: [target] };
const result = await removeContrller(initState);
...
you can then remove these lines
let state = { ...baselineAntState }; | |
beforeEach(() => { | |
state = { ...baselineAntState }; | |
}); |
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.
the intent is to always guarantee a fresh state object that wasn't manipulated in other tests, so a function or spreading the base state would achieve that
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.
🚀
No description provided.