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

chore(tests): add unit tests to contract functions #18

Merged
merged 3 commits into from
Dec 12, 2023

Conversation

atticusofsparta
Copy link
Contributor

No description provided.

@atticusofsparta atticusofsparta requested a review from a team as a code owner December 12, 2023 06:10
@codecov-commenter
Copy link

codecov-commenter commented Dec 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (441cf11) 7.90% compared to head (e4cbab8) 81.25%.

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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dtfiedler dtfiedler left a 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!

});

it.each(['hacker'])(
Copy link
Collaborator

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);
Copy link
Collaborator

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 };
Copy link
Collaborator

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

Comment on lines 27 to 31
let state = { ...baselineAntState };

beforeEach(() => {
state = { ...baselineAntState };
});
Copy link
Collaborator

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

Suggested change
let state = { ...baselineAntState };
beforeEach(() => {
state = { ...baselineAntState };
});

Copy link
Collaborator

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

Copy link
Collaborator

@dtfiedler dtfiedler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@atticusofsparta atticusofsparta merged commit 4c9866c into main Dec 12, 2023
5 checks passed
@atticusofsparta atticusofsparta deleted the add-unit-tests branch December 12, 2023 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants