Skip to content

Commit eed3789

Browse files
committed
address exercise feedback
1 parent c57ad1f commit eed3789

File tree

17 files changed

+74
-15
lines changed

17 files changed

+74
-15
lines changed

exercises/01.sunsetting-jsdom/01.solution.break-jsdom/src/file-preview.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { test, expect } from 'vitest'
21
import { render, screen } from '@testing-library/react'
32
import { FilePreview } from './file-preview.tsx'
43

exercises/01.sunsetting-jsdom/01.solution.break-jsdom/tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"compilerOptions": {
55
"target": "esnext",
66
"module": "preserve",
7-
"types": ["@vitest/browser/providers/playwright"]
7+
"types": ["vitest/globals"]
88
}
99
}

exercises/01.sunsetting-jsdom/01.solution.break-jsdom/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import react from '@vitejs/plugin-react'
55
export default defineConfig({
66
plugins: [react()],
77
test: {
8+
globals: true,
89
environment: 'jsdom',
910
},
1011
})

exercises/02.vitest-browser-mode/01.problem.installation-and-setup/README.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The installation step is done, and now it's time to configure Vitest is it can r
2929

3030
To enable the Browser Mode in Vitest, I need to set `test.browser.enabled` to `true` in my `vite.config.ts`/`vitest.config.ts`:
3131

32-
```ts filename=vite.config.ts add=9-11
32+
```ts filename=vite.config.ts remove=9 add=10-12
3333
/// <reference types="vitest" />
3434
import { defineConfig } from 'vite'
3535
import react from '@vitejs/plugin-react'
@@ -38,6 +38,7 @@ export default defineConfig({
3838
plugins: [react()],
3939
test: {
4040
globals: true,
41+
environment: 'jsdom',
4142
browser: {
4243
enabled: true,
4344
},

exercises/02.vitest-browser-mode/01.problem.installation-and-setup/tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"compilerOptions": {
55
"target": "esnext",
66
"module": "preserve",
7-
"types": ["@vitest/browser/providers/playwright"]
7+
"types": ["vitest/globals", "@vitest/browser/matchers"]
88
}
99
}

exercises/02.vitest-browser-mode/01.solution.installation-and-setup/README.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Installation and setup
22

3-
That's it! :tada: You have everything you need to finally start testing my browser code in the browser. Now, it's time to refactor the existing test to leverage the beauty of Vitest Browser Mode.
3+
That's it! :tada: You have everything you need to finally start testing your browser code in the browser.
4+
5+
If you try running tests right now, you will get an error:
6+
7+
```txt nonumber nocopy
8+
TestingLibraryElementError: Unable to find an element with the text: hello world. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
9+
```
10+
11+
This is because you have to refactor your test suite to correctly render your component in the browser. This is exactly what you are going to do in the next exercise.
412

513
## Related materials
614

exercises/02.vitest-browser-mode/01.solution.installation-and-setup/tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"compilerOptions": {
55
"target": "esnext",
66
"module": "preserve",
7-
"types": ["vitest/globals"]
7+
"types": ["vitest/globals", "@vitest/browser/matchers"]
88
}
99
}

exercises/02.vitest-browser-mode/02.problem.migrate-the-test/src/file-preview.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// 💣 Remove the import from `@testing-library/react`. You won't need it anymore.
22
import { render, screen } from '@testing-library/react'
3-
// 🐨 Import `page` from '@vitest/browser'
3+
// 🐨 Import `page` from '@vitest/browser/context'
44
// 💰 import { foo } from 'bar'
55
//
66
// 🐨 Import `render` from 'vitest-browser-react'.
@@ -10,7 +10,7 @@ import { FilePreview } from './file-preview.tsx'
1010
test('displays the preview card', async () => {
1111
render(<FilePreview file={new File(['hello world'], 'file.txt')} />)
1212

13-
// 🐨 Replace `expect()` with `expect.element()`.
13+
// 🐨 Replace `expect()` with `await expect.element()`.
1414
expect(
1515
// 🐨 Replace the `screen.getByText` function with
1616
// `page.getByText`.

exercises/02.vitest-browser-mode/02.problem.migrate-the-test/tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"compilerOptions": {
55
"target": "esnext",
66
"module": "preserve",
7-
"types": ["vitest/globals"]
7+
"types": ["vitest/globals", "@vitest/browser/matchers"]
88
}
99
}

exercises/02.vitest-browser-mode/02.solution.migrate-the-test/tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"compilerOptions": {
55
"target": "esnext",
66
"module": "preserve",
7-
"types": ["vitest/globals"]
7+
"types": ["vitest/globals", "@vitest/browser/matchers"]
88
}
99
}

0 commit comments

Comments
 (0)