Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Commit

Permalink
Correct and clarify HTML inputs
Browse files Browse the repository at this point in the history
E.g. `<div/>` is not valid in HTML documents, only in XHTML documents (which we’re not using here). It still appeared to work because the HTML parser is very forgiving, but this patch clarifies the intended result by explicitly including closing tags where applicable (even in cases where they are not strictly necessary for validity, like `<p>`).
  • Loading branch information
mathiasbynens committed Aug 31, 2020
1 parent ef02b21 commit b1688cd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/css-path.spec.ts
Expand Up @@ -27,53 +27,53 @@ describe('CSS Path', () => {
});

it('should return an id selector if the node has an id', () => {
document.body.innerHTML = `<div id="test" data-id="test" />`;
document.body.innerHTML = `<div id="test" data-id="test"></div>`;
const node = document.querySelector('[data-id="test"]');
const path = cssPath(node);
expect(path).toBe('#test');
});

it('should return a path until the document', () => {
document.body.innerHTML = `<div><p data-id="test"/></div>`;
document.body.innerHTML = `<div><p data-id="test"></p></div>`;
const node = document.querySelector('[data-id="test"]');
const path = cssPath(node);
expect(path).toBe('body > div > p');
});

it('should ignore siblings that are not element nodes', () => {
document.body.innerHTML = `<div data-id="test" ></div> Hello World`;
document.body.innerHTML = `<div data-id="test"></div> Hello World`;
const node = document.querySelector('[data-id="test"]');

const path = cssPath(node);
expect(path).toBe('body > div');
});

it('should index children with nth-child if there are siblings with the same tag name', () => {
document.body.innerHTML = `<p/><div></div><div data-id="test" ></div>`;
document.body.innerHTML = `<p></p><div></div><div data-id="test"></div>`;
const node = document.querySelector('[data-id="test"]');

const path = cssPath(node);
expect(path).toBe('body > div:nth-child(3)');
});

it('should not use nth-child if siblings with the same tag name are distinguishable by class name', () => {
document.body.innerHTML = `<div class="test1 test2"></div><div class="test2 test3" data-id="test" ></div>`;
document.body.innerHTML = `<div class="test1 test2"></div><div class="test2 test3" data-id="test"></div>`;
const node = document.querySelector('[data-id="test"]');

const path = cssPath(node);
expect(path).toBe('body > div.test3');
});

it('should use nth-child if siblings with the same tag name are not distinguishable by class name', () => {
document.body.innerHTML = `<div class="test1 test2"></div><div class="test2" data-id="test" ></div>`;
document.body.innerHTML = `<div class="test1 test2"></div><div class="test2" data-id="test"></div>`;
const node = document.querySelector('[data-id="test"]');

const path = cssPath(node);
expect(path).toBe('body > div:nth-child(2)');
});

it('should include the type for input elements', () => {
document.body.innerHTML = `<input type="email" data-id="test" />`;
document.body.innerHTML = `<input type="email" data-id="test">`;
const node = document.querySelector('[data-id="test"]');

const path = cssPath(node);
Expand Down

0 comments on commit b1688cd

Please sign in to comment.