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

Items counter test #76

Merged
merged 2 commits into from
May 18, 2022
Merged
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
31 changes: 31 additions & 0 deletions src/__tests__/itemsCounter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import UserInterface from '../modules/userInterface.js';

describe('Counting number of items', () => {
beforeEach(() => {
document.body.innerHTML = `
<div>
<ul class="recipes__list">
</ul>
</div>`;
});
it('Returns 0 if there are no items present in the List', () => {
expect(UserInterface.itemCount()).toBe(0);
});

it('Returns 1 when an item get added to the list.', () => {
const LIST = document.querySelector('.recipes__list');
const LI = document.createElement('li');
LIST.appendChild(LI);
expect(UserInterface.itemCount()).toBe(1);
});

it('Returns n when n items get added to the list', () => {
const LIST = document.querySelector('.recipes__list');
const n = 8;
for (let i = 0; i < n; i += 1) {
const LI = document.createElement('li');
LIST.appendChild(LI);
}
expect(UserInterface.itemCount()).toBe(n);
});
});