Skip to content

Commit a642548

Browse files
test(js): add tests for getHTMLElement
1 parent 6bdbf0e commit a642548

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1+
import { getHTMLElement } from '../getHTMLElement';
2+
13
describe('getHTMLElement', () => {
2-
test.todo('with element returns the element');
4+
afterEach(() => {
5+
document.body.innerHTML = '';
6+
});
7+
8+
test('with element returns the element', () => {
9+
const element = document.createElement('div');
10+
document.body.appendChild(element);
11+
12+
expect(getHTMLElement(element)).toEqual(element);
13+
});
14+
15+
test('with a string returns the element if exists', () => {
16+
const element = document.createElement('div');
17+
document.body.appendChild(element);
318

4-
test.todo('with a string returns the element if exists');
19+
expect(getHTMLElement('div')).toEqual(element);
20+
});
521

6-
test.todo('with a string throws invariant if does not exist');
22+
test('with a string throws invariant if does not exist', () => {
23+
expect(() => {
24+
getHTMLElement('div');
25+
}).toThrow('The element "div" is not in the document.');
26+
});
727
});

0 commit comments

Comments
 (0)