-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to a new model closer mimicking the web APIs
I am using `activeNode` instead of `pivot` now which is sort of cheating but also kind of makes sense.
- Loading branch information
1 parent
7509718
commit 8ad4282
Showing
2 changed files
with
124 additions
and
152 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
import { test, expect } from 'bun:test'; | ||
|
||
// TODO: Introduce `*Test` types which do not have the circular references as | ||
// base types for the actually exposed types | ||
import DOMParser from './index'; | ||
|
||
test('one element', async () => { | ||
test('HTML', async () => { | ||
const domParser = new DOMParser(); | ||
const document = await domParser.parseFromString('<html></html>'); | ||
expect(document.body.outerHTML).toEqual(`<body></body>`); | ||
}); | ||
|
||
test('HEAD', async () => { | ||
const domParser = new DOMParser(); | ||
const document = await domParser.parseFromString('<body></body>', 'text/html'); | ||
expect(document).toEqual({ | ||
body: { | ||
tagName: 'body', | ||
children: [], | ||
} | ||
}); | ||
const document = await domParser.parseFromString('<head></head>'); | ||
expect(document.head.outerHTML).toEqual(`<head></head>`); | ||
expect(document.body.outerHTML).toEqual(`<body></body>`); | ||
}); | ||
|
||
test('two elements', async () => { | ||
test('BODY', async () => { | ||
const domParser = new DOMParser(); | ||
const document = await domParser.parseFromString('<head></head><body></body>', 'text/html'); | ||
expect(document).toEqual({ | ||
body: { | ||
tagName: 'body', | ||
children: [], | ||
} | ||
}); | ||
const document = await domParser.parseFromString('<body></body>'); | ||
expect(document.head.outerHTML).toEqual(`<head></head>`); | ||
expect(document.body.outerHTML).toEqual(`<body></body>`); | ||
}); | ||
|
||
test('normal element', async () => { | ||
test('HEAD & BODY', async () => { | ||
const domParser = new DOMParser(); | ||
const document = await domParser.parseFromString('<body><a></a></body>', 'text/html'); | ||
expect(document).toEqual({ | ||
body: { | ||
tagName: 'body', | ||
children: [ | ||
{ | ||
tagName: 'a', | ||
children: [], | ||
} | ||
], | ||
} | ||
}); | ||
const document = await domParser.parseFromString('<head></head><body></body>'); | ||
expect(document.head.outerHTML).toEqual(`<head></head>`); | ||
expect(document.body.outerHTML).toEqual(`<body></body>`); | ||
}); | ||
|
||
test('H1', async () => { | ||
const domParser = new DOMParser(); | ||
const document = await domParser.parseFromString('<h1></h1>'); | ||
expect(document.body.outerHTML).toEqual(`<body><h1></h1></body>`); | ||
}); | ||
|
||
test('H1 & H2 & H3', async () => { | ||
const domParser = new DOMParser(); | ||
const document = await domParser.parseFromString('<h1></h1><h2></h2><h3></h3>'); | ||
expect(document.body.outerHTML).toEqual(`<body><h1></h1><h2></h2><h3></h3></body>`); | ||
}); | ||
|
||
// TODO: Use http://info.cern.ch/hypertext/WWW/TheProject.html as one of the tests |
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