Я просто создал html документ. я начинаю тестировать, используя jest
. Но получаю неверный вывод. Как правильно проверить существование элемента в документе с помощью jest
?
вот мой html:
<body>
<h2>Title</h2>
<input type="file" name="" class='title'>
<script src="./index.js"></script>
</body>
мой js код:
window.onload = () => {
const title = document.querySelector('h2');
title.style = 'border:1px solid red';
const input = document.querySelector('input');
input.addEventListener('change', (event) => {
const file = event.srcElement.files;
input.value = '';
});
}
my test spe c:
describe('first test', () => {
it('should contain h2 element', () => {
const h2 = document.querySelector('h2');
expect(document.contains(h2)).toBe(true);
});
});
, но ошибка ниже:
expect(received).toBe(expected) // Object.is equality
Expected: true
Received: false
3 | it('should contain h2 element', () => {
4 | const h2 = document.querySelector('h2');
> 5 | expect(document.contains(h2)).toBe(true);
| ^
6 | });
7 |
8 | });
at Object.<anonymous> (index.spec.js:5:39)
каков правильный подход для проверки моего существующего элемента в документе?
Заранее спасибо.