Skip to content

Commit

Permalink
add tests for 06
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Aug 22, 2024
1 parent ede24c9 commit 8cff5a9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
24 changes: 24 additions & 0 deletions exercises/06.arrays/01.solution.key-prop/key.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'

const originalError = console.error
const errors: Array<string> = []
console.error = (...args: any[]) => {
errors.push(args[0])
originalError(...args)
}

import './index.tsx'

const { screen } = dtl

await testStep('Wait for Add Item button', async () => {
await screen.findByRole('button', { name: /add item/i })
})

await testStep('Key prop is provided (no console errors)', async () => {
try {
expect(errors).toHaveLength(0)
} finally {
console.error = originalError
}
})
24 changes: 24 additions & 0 deletions exercises/06.arrays/02.solution.focus-state/key.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'

const originalError = console.error
const errors: Array<string> = []
console.error = (...args: any[]) => {
errors.push(args[0])
originalError(...args)
}

import './index.tsx'

const { screen } = dtl

await testStep('Wait for things to render', async () => {
await screen.findByText('Without a key')
})

await testStep('Key prop is provided (no console errors)', async () => {
try {
expect(errors).toHaveLength(0)
} finally {
console.error = originalError
}
})
5 changes: 5 additions & 0 deletions exercises/06.arrays/03.solution.key-reset/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, testStep } from '@epic-web/workshop-utils/test'

await testStep('this is just a demo', () => {
expect(true).toBe(true)
})

0 comments on commit 8cff5a9

Please sign in to comment.