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

[Fixes] Code Coverage: Create tests for src/index.ts #296

Conversation

SiddheshKukade
Copy link
Member

@SiddheshKukade SiddheshKukade commented Mar 19, 2022

What kind of change does this PR introduce?
Added Testcases for src/state/index.ts file

Issue Number:
#278

Fixes #278

Did you add tests for your changes?
Yes I have added a testfile

Summary
I have added a index.test.ts. file required for the issue #278 for Gsoc2022

Does this PR introduce a breaking change?
No

SnapShots

image

Have you read the contributing guide?
Yes

@SiddheshKukade SiddheshKukade changed the title 🤖 TEST: src/index.ts testing added TEST: src/index.ts testing added Mar 19, 2022
@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2022

Codecov Report

Merging #296 (362b201) into develop (b462cca) will increase coverage by 5.98%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop     #296      +/-   ##
===========================================
+ Coverage    40.22%   46.20%   +5.98%     
===========================================
  Files           45       45              
  Lines          711      699      -12     
  Branches       149      149              
===========================================
+ Hits           286      323      +37     
+ Misses         410      364      -46     
+ Partials        15       12       -3     
Impacted Files Coverage Δ
src/components/EventListCard/EventListCard.tsx 100.00% <0.00%> (+56.25%) ⬆️
...components/OrgPeopleListCard/OrgPeopleListCard.tsx 100.00% <0.00%> (+58.82%) ⬆️
src/components/OrgPostCard/OrgPostCard.tsx 100.00% <0.00%> (+63.63%) ⬆️
...components/MemberRequestCard/MemberRequestCard.tsx 100.00% <0.00%> (+65.21%) ⬆️
...ponents/AddOn/core/AddOnRegister/AddOnRegister.tsx 100.00% <0.00%> (+100.00%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@SiddheshKukade SiddheshKukade changed the title TEST: src/index.ts testing added [Fixes] Code Coverage: Create tests for src/index.ts Mar 19, 2022
@palisadoes
Copy link
Contributor

palisadoes commented Mar 19, 2022

Please make sure the issue is assigned to you before making the pull request. We may close PRs for which there is no assigned issue.

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

You will need to get to 100% coverage for the review to be done.

@SiddheshKukade
Copy link
Member Author

Please make sure the issue is assigned to you before making the pull request. We may close PRs for which there is no assigned issue.

I am sorry sir , I'll keep that in mind next time

@yasharth291
Copy link
Contributor

Please make sure the issue is assigned to you before making the pull request. We may close PRs for which there is no assigned issue.

the thing doesn't work like this it shows the percent of whole code coverage if it is a + then it is okay

Copy link
Contributor

@yasharth291 yasharth291 left a comment

Choose a reason for hiding this comment

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

explain the test like which things they are doing and what is the expected result for the same

@SiddheshKukade
Copy link
Member Author

SiddheshKukade commented Mar 21, 2022

@palisadoes @yasharth291 sir I am very confused currently,

#278 Issue is asking to test the src/state/index.ts file which contains the following code (there is only 1 line in the file)

export * as actionCreators from './action-creators/index';

I thought I have to test the actionCreators object to have truth values so I added the below code

test('Testing Index File of "src/state/"', () => {
    expect(actionCreators.installPlugin).toBeTruthy();
    expect(actionCreators.removePlugin).toBeTruthy();
    expect(actionCreators.updateInstalled).toBeTruthy();
    expect(actionCreators.updatePluginLinks).toBeTruthy();
    })

still I am getting coverage of 33% only....
Is there anything I am missing ??
help me @palisadoes @yasharth291

@yasharth291
Copy link
Contributor

try asking @asmitsirohi he will tell you

@Devesh21700Kumar
Copy link

@palisadoes @yasharth291 sir I am very confused currently,

#278 Issue is asking to test the src/state/index.ts file which contains the following code (there is only 1 line in the file)

export * as actionCreators from './action-creators/index';

I thought I have to test the actionCreators object to have truth values so I added the below code

test('Testing Index File of "src/state/"', () => {
    expect(actionCreators.installPlugin).toBeTruthy();
    expect(actionCreators.removePlugin).toBeTruthy();
    expect(actionCreators.updateInstalled).toBeTruthy();
    expect(actionCreators.updatePluginLinks).toBeTruthy();
    })

still I am getting coverage of 33% only.... Is there anything I am missing ?? help me @palisadoes @yasharth291

You'll have to probably mock the state data and check the dispatch actions by using isEqualTo method.

@palisadoes
Copy link
Contributor

Thanks @Devesh21700Kumar. Can you provide an example in an existing test suite in the repo?

@Devesh21700Kumar
Copy link

Thanks @Devesh21700Kumar. Can you provide an example in an existing test suite in the repo?

Mocks have been created in children files of screen subFolder

https://github.com/PalisadoesFoundation/talawa-admin/blob/develop/src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx

but they are Mocks for graphql queries and therefore are in a bit different format from what is needed.
Exact snippet that can be referred to for this case is not present right now i guess

@asmitsirohi
Copy link

@SiddheshKukade, You are trying to test an actionCreaters by importing it, instead of the index file. Leave it for actionCreaters tests, for this, you have to mock the data.

image

Actually, the src/state/index file has only one export statement, which is not necessary to test. Just to get 100% code coverage we can exclude it from code coverage, by referring to this article https://stackoverflow.com/questions/43044696/test-a-create-react-app-index-js-file.

What's your view on this @yasharth291 @palisadoes.

@SiddheshKukade
Copy link
Member Author

@SiddheshKukade, You are trying to test an actionCreaters by importing it, instead of the index file. Leave it for actionCreaters tests, for this, you have to mock the data.

image

Actually, the src/state/index file has only one export statement, which is not necessary to test. Just to get 100% code coverage we can exclude it from code coverage, by referring to this article https://stackoverflow.com/questions/43044696/test-a-create-react-app-index-js-file.

What's your view on this @yasharth291 @palisadoes.

OK @asmitsirohi sir I will try this one

…e(src/state/index.ts) as it contains only 1 line
@SiddheshKukade
Copy link
Member Author

SiddheshKukade commented Mar 22, 2022

@asmitsirohi @palisadoes @yasharth291 @Devesh21700Kumar what do you guys think about this change
just added the below code in package json jest object

  "coveragePathIgnorePatterns": ["src/state/index.ts"]

so that it will not look for the src/state/index file as it contains one import statement

@Sagar2366 Sagar2366 requested a review from DangaRanga March 22, 2022 12:14
@Sagar2366 Sagar2366 added the test Testing application label Mar 22, 2022
Copy link
Contributor

@DangaRanga DangaRanga left a comment

Choose a reason for hiding this comment

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

I apologize for the delayed review. This is good actually since the index.ts file only contains an import statement

@SiddheshKukade
Copy link
Member Author

thank you @DangaRanga sir, @palisadoes @yasharth291 are the changes ok?

@palisadoes palisadoes merged commit 0b0baaa into PalisadoesFoundation:develop Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Testing application
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code Coverage: Create tests for index.ts
8 participants