-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Document parser has been brought back (#33)
- Loading branch information
Showing
3 changed files
with
61 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { expect } from 'chai' | ||
|
||
const html = ` | ||
<html> | ||
<p something="yo">hello</p> | ||
</html> | ||
` | ||
|
||
describe("Document", () => { | ||
it('exists', () => { | ||
expect(typeof Document).to.equal('function') | ||
}) | ||
|
||
it("parses html into a queryable dom tree", function () { | ||
const dom = Document.parse(html) | ||
expect(dom).to.be.instanceof(Document) | ||
const p = dom.querySelector("p") | ||
expect(p).to.be.instanceof(Element) | ||
expect(p.getAttribute("something")).to.equal("yo") | ||
}) | ||
|
||
it('can stringify a DOM', () => { | ||
const doc = Document.parse(html) | ||
expect(doc.documentElement.outerHTML).to.equal(html) | ||
}) | ||
|
||
it('can replace elements', () => { | ||
const doc = Document.parse(html) | ||
doc.querySelector("p").replaceWith("<div>booya</div>") | ||
expect(doc.querySelector("div").textContent).to.equal("booya") | ||
}) | ||
}) |