Created
July 16, 2021 21:54
-
-
Save mauteri/55f87b8ae004b6abb77822b37d4fd625 to your computer and use it in GitHub Desktop.
addListItem DOM Manipulation Jest Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {addListItem} from '../index'; | |
describe('addListItem', () => { | |
beforeAll(() => { | |
document.body.innerHTML = '<ul id="unittest"></ul>'; | |
const $el = document.getElementById('unittest') | |
addListItem($el, 'First'); | |
addListItem($el, 'Second'); | |
addListItem($el, 'Third'); | |
}); | |
afterAll(() => { | |
document.body.innerHTML = ''; | |
}); | |
test('Number of items is 3', () => { | |
const count = document.getElementById('unittest').getElementsByTagName('li').length; | |
expect(count).toBe(3); | |
}); | |
test('First element has text First', () => { | |
const text = document.getElementById('unittest').getElementsByTagName('li')[0].textContent; | |
expect(text).toBe('First'); | |
}); | |
test('Second element has text Second', () => { | |
const text = document.getElementById('unittest').getElementsByTagName('li')[1].textContent; | |
expect(text).toBe('Second'); | |
}); | |
test('Third element has text Third', () => { | |
const text = document.getElementById('unittest').getElementsByTagName('li')[2].textContent; | |
expect(text).toBe('Third'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment