Skip to content

Commit 8bac9cc

Browse files
committed
finish tests
1 parent c141427 commit 8bac9cc

File tree

21 files changed

+416
-6
lines changed

21 files changed

+416
-6
lines changed

exercises/01.js-hello-world/01.solution.hello/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { expect, testStep } from '@epic-web/workshop-utils/test'
22

3-
await testStep('Hello is rendered to the DOM', () => {
3+
await testStep('"Hello World" is rendered to the DOM', () => {
44
const rootElement = document.getElementById('root')
55
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
66

77
const element = rootElement!.querySelector('.container')
8-
expect(element, 'element not found').to.be.instanceOf(HTMLElement)
8+
expect(element, 'container element not found').to.be.instanceOf(HTMLElement)
99

1010
expect(element!.textContent, 'element text is not correct').to.equal(
1111
'Hello World',

exercises/01.js-hello-world/02.solution.root/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { expect, testStep } from '@epic-web/workshop-utils/test'
22

3-
await testStep('Hello is rendered to the DOM', () => {
3+
await testStep('"Hello World" is rendered to the DOM', () => {
44
const rootElement = document.getElementById('root')
55
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
66

77
const element = rootElement!.querySelector('.container')
8-
expect(element, 'element not found').to.be.instanceOf(HTMLElement)
8+
expect(element, 'container element not found').to.be.instanceOf(HTMLElement)
99

1010
expect(element!.textContent, 'element text is not correct').to.equal(
1111
'Hello World',

exercises/02.raw-react/01.solution.elements/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { expect, testStep } from '@epic-web/workshop-utils/test'
22

3-
await testStep('Hello is rendered to the DOM', () => {
3+
await testStep('"Hello World" is rendered to the DOM', () => {
44
const rootElement = document.getElementById('root')
55
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
66

77
const element = rootElement!.querySelector('.container')
8-
expect(element, 'element not found').to.be.instanceOf(HTMLElement)
8+
expect(element, 'container element not found').to.be.instanceOf(HTMLElement)
99

1010
expect(element!.textContent, 'element text is not correct').to.equal(
1111
'Hello World',
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect, testStep } from '@epic-web/workshop-utils/test'
2+
3+
await testStep('"Hello World" is rendered to the DOM', () => {
4+
const rootElement = document.getElementById('root')
5+
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
6+
if (!rootElement) return
7+
8+
const element = rootElement.querySelector('.container')
9+
expect(element, 'container element not found').to.be.instanceOf(HTMLElement)
10+
if (!element) return
11+
12+
if (element.textContent === 'HelloWorld') {
13+
throw new Error(
14+
'Looks like you forgot to include the space between the spans',
15+
)
16+
}
17+
18+
expect(element.textContent, 'element text is not correct').to.equal(
19+
'Hello World',
20+
)
21+
22+
const [hello, world] = element.querySelectorAll('span')
23+
24+
expect(hello, 'Hello span not found').to.be.instanceOf(HTMLElement)
25+
expect(world, 'World span not found').to.be.instanceOf(HTMLElement)
26+
27+
expect(hello.textContent, 'hello text is not correct').to.equal('Hello')
28+
expect(world.textContent, 'world text is not correct').to.equal('World')
29+
})
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect, testStep } from '@epic-web/workshop-utils/test'
2+
3+
await testStep('Proper elements are rendered to the DOM', () => {
4+
const rootElement = document.getElementById('root')
5+
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
6+
if (!rootElement) return
7+
8+
const element = rootElement.querySelector('.container')
9+
expect(element, 'container element not found').to.be.instanceOf(HTMLElement)
10+
if (!element) return
11+
12+
const p = element.querySelector('p')
13+
expect(p, '<p> not found').to.be.instanceOf(HTMLElement)
14+
const ul = element.querySelector('ul')
15+
expect(ul, '<ul> not found').to.be.instanceOf(HTMLElement)
16+
const lis = element.querySelectorAll('li')
17+
expect(lis, '<li> elements not found').to.have.length(2)
18+
19+
expect(p!.textContent, 'p text is not correct').to.equal(
20+
"Here's Sam's favorite food:",
21+
)
22+
23+
const [greenEggs, ham] = ul!.querySelectorAll('li')
24+
25+
expect(greenEggs.textContent, 'green eggs text is not correct').to.equal(
26+
'Green eggs',
27+
)
28+
expect(ham.textContent, 'ham text is not correct').to.equal('Ham')
29+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect, testStep } from '@epic-web/workshop-utils/test'
2+
3+
// wait for babel to compile and evaluate the JSX
4+
await new Promise(resolve => setTimeout(resolve, 100))
5+
6+
await testStep('"Hello World" is rendered to the DOM', () => {
7+
const rootElement = document.getElementById('root')
8+
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
9+
10+
const element = rootElement!.querySelector('.container')
11+
expect(element, 'container element not found').to.be.instanceOf(HTMLElement)
12+
13+
expect(element!.textContent, 'element text is not correct').to.equal(
14+
'Hello World',
15+
)
16+
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { expect, testStep } from '@epic-web/workshop-utils/test'
2+
3+
const response = await fetch(location.href)
4+
const indexHtml = await response.text()
5+
const node = document.createElement('div')
6+
node.innerHTML = indexHtml
7+
8+
const inlineScript = node.querySelector('script[type="text/babel"]')
9+
await testStep('script with type text/babel exists', () => {
10+
expect(
11+
inlineScript,
12+
'script with type text/babel not found',
13+
).to.be.instanceOf(HTMLScriptElement)
14+
})
15+
16+
await testStep('script with type text/babel has data-type="module"', () => {
17+
expect(
18+
inlineScript!.getAttribute('data-type'),
19+
'script with type text/babel does not have data-type="module"',
20+
).to.equal('module')
21+
})
22+
23+
await testStep('babel is loaded', () => {
24+
const script = node.querySelector('script[src="/babel-standalone.js"]')
25+
expect(
26+
script,
27+
'babel script not found, did you remember to add a script for "/babel-standalone.js" as the src?',
28+
).to.be.instanceOf(HTMLScriptElement)
29+
})
30+
31+
await testStep('JSX is in use', async () => {
32+
expect(
33+
inlineScript!.textContent,
34+
'createElement( should not appear in your source',
35+
).not.to.include('createElement(')
36+
expect(inlineScript!.textContent, 'JSX is not in use').to.include('</div>')
37+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect, testStep } from '@epic-web/workshop-utils/test'
2+
3+
// wait for babel to compile and evaluate the JSX
4+
await new Promise(resolve => setTimeout(resolve, 100))
5+
6+
await testStep('"Hello World" is rendered to the DOM', () => {
7+
const rootElement = document.getElementById('root')
8+
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
9+
10+
const element = rootElement!.querySelector('.container')
11+
expect(element, 'container element not found').to.be.instanceOf(HTMLElement)
12+
13+
expect(element!.textContent, 'element text is not correct').to.equal(
14+
'Hello World',
15+
)
16+
})
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+
const response = await fetch(location.href)
4+
const indexHtml = await response.text()
5+
const node = document.createElement('div')
6+
node.innerHTML = indexHtml
7+
8+
const inlineScript = node.querySelector('script[type="text/babel"]')
9+
if (!inlineScript) {
10+
throw new Error('inlineScript not found')
11+
}
12+
13+
await testStep('className is interpolated', async () => {
14+
expect(inlineScript.textContent).to.include('className={')
15+
expect(inlineScript.textContent).not.to.include('className="')
16+
})
17+
18+
await testStep('children is interpolated', async () => {
19+
expect(
20+
inlineScript.textContent,
21+
'children should be interpolated',
22+
).not.to.include('>Hello World<')
23+
expect(inlineScript.textContent).to.include('{children}')
24+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect, testStep } from '@epic-web/workshop-utils/test'
2+
3+
// wait for babel to compile and evaluate the JSX
4+
await new Promise(resolve => setTimeout(resolve, 100))
5+
6+
await testStep('"Hello World" is rendered to the DOM', () => {
7+
const rootElement = document.getElementById('root')
8+
expect(rootElement, 'root element not found').to.be.instanceOf(HTMLElement)
9+
10+
const element = rootElement!.querySelector('.container')
11+
expect(element, 'container element not found').to.be.instanceOf(HTMLElement)
12+
13+
expect(element!.textContent, 'element text is not correct').to.equal(
14+
'Hello World',
15+
)
16+
})

0 commit comments

Comments
 (0)