Skip to content

Commit

Permalink
Merge pull request #31 from David-Kasilia/commentsCounterTests
Browse files Browse the repository at this point in the history
Comments counter tests:
  • Loading branch information
HabibPayenda committed Sep 2, 2022
2 parents de26fe6 + 182fc62 commit f52fdb8
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 230 deletions.
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);
});
});

0 comments on commit f52fdb8

Please sign in to comment.