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

Comments counter tests: #31

Merged
merged 2 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions __mocks__/commentsCounter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default (data) => {
let count = 0;
if (data && data.length > 0) {
count = data.length;
}
return count;
};
22 changes: 22 additions & 0 deletions __mocks__/commentsData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default [
{
user_id: 1,
name: 'name',
comment: 'comment',
},
{
user_id: 2,
name: 'name',
comment: 'comment',
},
{
user_id: 3,
name: 'name',
comment: 'comment',
},
{
user_id: 4,
name: 'name',
comment: 'comment',
},
];
17 changes: 17 additions & 0 deletions __test__/commentsCounter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import commentsCounter from '../__mocks__/commentsCounter.js';
import data from '../__mocks__/commentsData.js';

describe('Testing commentsCounterFunction', () => {
it('should return the correct number of comments', () => {
const count = commentsCounter(data);
expect(count).toBe(4);
});

it('should have a length of greater than 0', () => {
const value = 0;

const count = commentsCounter(data);

expect(count).toBeGreaterThan(value);
});
});