Skip to content

Commit 93ab08b

Browse files
committed
progress on tests
1 parent b171459 commit 93ab08b

File tree

6 files changed

+5195
-106
lines changed

6 files changed

+5195
-106
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect, testStep } from '@epic-web/workshop-utils/test'
2+
3+
await testStep('Hello is rendered to the DOM', () => {
4+
const rootElement = document.getElementById('root')
5+
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
6+
7+
const element = rootElement!.querySelector('.container')
8+
expect(element, 'element not found').to.be.instanceOf(HTMLElement)
9+
10+
expect(element!.textContent, 'element text is not correct').to.equal(
11+
'Hello World',
12+
)
13+
})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect, testStep } from '@epic-web/workshop-utils/test'
2+
3+
await testStep('Hello is rendered to the DOM', () => {
4+
const rootElement = document.getElementById('root')
5+
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
6+
7+
const element = rootElement!.querySelector('.container')
8+
expect(element, 'element not found').to.be.instanceOf(HTMLElement)
9+
10+
expect(element!.textContent, 'element text is not correct').to.equal(
11+
'Hello World',
12+
)
13+
})
14+
15+
await testStep('root element is not in the HTML', async () => {
16+
const response = await fetch(location.href)
17+
const text = await response.text()
18+
const node = document.createElement('div')
19+
node.innerHTML = text
20+
expect(
21+
node.querySelector('#root'),
22+
'root element found in the HTML when it should not be',
23+
).to.be.null
24+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, testStep } from '@epic-web/workshop-utils/test'
2+
3+
await testStep('Hello is rendered to the DOM', () => {
4+
const rootElement = document.getElementById('root')
5+
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
6+
7+
const element = rootElement!.querySelector('.container')
8+
expect(element, 'element not found').to.be.instanceOf(HTMLElement)
9+
10+
expect(element!.textContent, 'element text is not correct').to.equal(
11+
'Hello World',
12+
)
13+
})
14+
15+
await testStep('The DOM element is created by React', () => {
16+
const element = document.querySelector('#root .container')
17+
expect(element, 'element not found').to.be.instanceOf(HTMLElement)
18+
if (!element) return
19+
20+
const reactKeys = Object.keys(element).filter(key =>
21+
key.startsWith('__react'),
22+
)
23+
expect(
24+
reactKeys.length,
25+
'element was not created by React',
26+
).to.be.greaterThan(0)
27+
})

0 commit comments

Comments
 (0)