1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
const createTestElement = () => {
const element = document.createElement('div');
element.textContent = 'Hello World!';
return element;
};
describe('DOM patch for getClientRects', () => {
let origHtml;
let el;
beforeEach(() => {
origHtml = document.body.innerHTML;
el = createTestElement();
});
afterEach(() => {
document.body.innerHTML = origHtml;
});
describe('toBeVisible matcher', () => {
describe('when not attached to document', () => {
it('does not match', () => {
expect(el).not.toBeVisible();
});
});
describe('when attached to document', () => {
beforeEach(() => {
document.body.appendChild(el);
});
it('matches', () => {
expect(el).toBeVisible();
});
});
describe('with parent and attached to document', () => {
let parentEl;
beforeEach(() => {
parentEl = createTestElement();
parentEl.appendChild(el);
document.body.appendChild(parentEl);
});
it('matches', () => {
expect(el).toBeVisible();
});
describe.each`
style
${{ display: 'none' }}
${{ visibility: 'hidden' }}
`('with style $style', ({ style }) => {
it('does not match when applied to element', () => {
Object.assign(el.style, style);
expect(el).not.toBeVisible();
});
it('does not match when applied to parent', () => {
Object.assign(parentEl.style, style);
expect(el).not.toBeVisible();
});
});
});
});
});
|