Skip to content

Commit 69cc630

Browse files
committed
fix tests for 1.2
1 parent 9dc2b85 commit 69cc630

2 files changed

Lines changed: 64 additions & 10 deletions

File tree

exercises/01.exercise-navigation/02.problem.multi-step/index.test.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'node:assert'
22
import test from 'node:test'
33

4-
test('server responds with goodbye world', async (t) => {
4+
test('server responds with counter app HTML', async (t) => {
55
process.env.PORT ??= 4000
66
const { server } = await import('./index.js')
77
await new Promise((resolve) => {
@@ -11,10 +11,37 @@ test('server responds with goodbye world', async (t) => {
1111
try {
1212
const response = await fetch(`http://localhost:${process.env.PORT}`)
1313
const text = await response.text()
14-
assert.strictEqual(
15-
text,
16-
'goodbye world',
17-
'🚨 Make sure to update the server response to say "goodbye world" instead of "hello world"',
14+
15+
// Verify it's HTML
16+
assert.ok(
17+
response.headers.get('content-type').includes('text/html'),
18+
'Response should be HTML'
19+
)
20+
21+
// Verify the HTML contains key elements of the counter app
22+
assert.ok(
23+
text.includes('<title>Counter App</title>'),
24+
'HTML should include Counter App title'
25+
)
26+
assert.ok(
27+
text.includes('id="count"'),
28+
'HTML should include count element'
29+
)
30+
assert.ok(
31+
text.includes('id="increment"'),
32+
'HTML should include increment button'
33+
)
34+
assert.ok(
35+
text.includes('let count = 0'),
36+
'HTML should include counter JavaScript logic'
37+
)
38+
assert.ok(
39+
text.includes('button.addEventListener'),
40+
'HTML should include event listener for button clicks'
41+
)
42+
assert.ok(
43+
text.includes('count++'),
44+
'HTML should include code to increment the count'
1845
)
1946
} finally {
2047
await new Promise((resolve) => {

exercises/01.exercise-navigation/02.solution.multi-step/index.test.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'node:assert'
22
import test from 'node:test'
33

4-
test('server responds with goodbye world', async (t) => {
4+
test('server responds with counter app HTML', async (t) => {
55
process.env.PORT ??= 4000
66
const { server } = await import('./index.js')
77
await new Promise((resolve) => {
@@ -11,10 +11,37 @@ test('server responds with goodbye world', async (t) => {
1111
try {
1212
const response = await fetch(`http://localhost:${process.env.PORT}`)
1313
const text = await response.text()
14-
assert.strictEqual(
15-
text,
16-
'goodbye world',
17-
'🚨 Make sure to update the server response to say "goodbye world" instead of "hello world"',
14+
15+
// Verify it's HTML
16+
assert.ok(
17+
response.headers.get('content-type').includes('text/html'),
18+
'Response should be HTML'
19+
)
20+
21+
// Verify the HTML contains key elements of the counter app
22+
assert.ok(
23+
text.includes('<title>Counter App</title>'),
24+
'HTML should include Counter App title'
25+
)
26+
assert.ok(
27+
text.includes('id="count"'),
28+
'HTML should include count element'
29+
)
30+
assert.ok(
31+
text.includes('id="increment"'),
32+
'HTML should include increment button'
33+
)
34+
assert.ok(
35+
text.includes('let count = 0'),
36+
'HTML should include counter JavaScript logic'
37+
)
38+
assert.ok(
39+
text.includes('button.addEventListener'),
40+
'HTML should include event listener for button clicks'
41+
)
42+
assert.ok(
43+
text.includes('count++'),
44+
'HTML should include code to increment the count'
1845
)
1946
} finally {
2047
await new Promise((resolve) => {

0 commit comments

Comments
 (0)