Giter VIP home page Giter VIP logo

testing-react-apps's Introduction

Learn the essential tools and techniques to ship with confidence

In this hands-on workshop you'll learn everything you need to test React components and applications with ease and get the knowledge you need to ship your applications with confidence.

Learn React from Start to Finish

Build Status All Contributors GPL 3.0 License Code of Conduct Gitpod ready-to-code

Prerequisites

NOTE: The EpicReact.dev videos were recorded with React version ^16.13 and all material in this repo has been updated to React version ^18. Differences are minor and any relevant differences are noted in the instructions.

Quick start

It's recommended you run everything in the same environment you work in every day, but if you don't want to set up the repository locally, you can get started in one click with Gitpod, CodeSandbox, or by following the video demo instructions for GitHub Codespaces.

Open in Gitpod

For a local development environment, follow the instructions below

System Requirements

All of these must be available in your PATH. To verify things are set up properly, you can run this:

git --version
node --version
npm --version

If you have trouble with any of these, learn more about the PATH environment variable and how to fix it here for windows or mac/linux.

Setup

If you want to commit and push your work as you go, you'll want to fork first and then clone your fork rather than this repo directly.

After you've made sure to have the correct things (and versions) installed, you should be able to just run a few commands to get set up:

git clone https://github.com/kentcdodds/testing-react-apps.git
cd testing-react-apps
node setup

This may take a few minutes. It will ask you for your email. This is optional and just automatically adds your email to the links in the project to make filling out some forms easier.

If you get any errors, please read through them and see if you can find out what the problem is. If you can't work it out on your own then please file an issue and provide all the output from the commands you ran (even if it's a lot).

If you can't get the setup script to work, then just make sure you have the right versions of the requirements listed above, and run the following commands:

npm install
npm run validate

If you are still unable to fix issues and you know how to use Docker 🐳 you can setup the project with the following command:

docker-compose up

Running the app

For this one, there's not much to the app itself. The whole reason we have the app is just so you can see examples of the components that we'll be testing. You'll spend most of your time in the tests.

To get the app up and running, run:

npm start

This should start up your browser. If you're familiar, this is a standard react-scripts application.

You can also open the deployment of the app on Netlify.

Running the tests

npm test

This will start Jest in watch mode. Read the output and play around with it. The tests are there to help you reach the final version, however sometimes you can accomplish the task and the tests still fail if you implement things differently than I do in my solution, so don't look to them as a complete authority.

Exercises

  • src/__tests__/exercise/00.md: Background, Exercise Instructions, Extra Credit
  • src/__tests__/exercise/00.js: Exercise with Emoji helpers
  • src/__tests__/final/00.js: Final version
  • src/__tests__/final/00.extra-0.js: Final version of extra credit

The purpose of the exercise is not for you to work through all the material. It's intended to get your brain thinking about the right questions to ask me as I walk through the material.

Helpful Emoji 🐨 πŸ’ͺ 🏁 πŸ’° πŸ’― πŸ¦‰ πŸ“œ πŸ’£ πŸ‘¨β€πŸ’Ό 🚨

Each exercise has comments in it to help you get through the exercise. These fun emoji characters are here to help you.

  • Kody the Koala 🐨 will tell you when there's something specific you should do
  • Matthew the Muscle πŸ’ͺ will indicate that you're working with an exercise
  • Chuck the Checkered Flag 🏁 will indicate that you're working with a final version
  • Marty the Money Bag πŸ’° will give you specific tips (and sometimes code) along the way
  • Hannah the Hundred πŸ’― will give you extra challenges you can do if you finish the exercises early.
  • Olivia the Owl πŸ¦‰ will give you useful tidbits/best practice notes and a link for elaboration and feedback.
  • Dominic the Document πŸ“œ will give you links to useful documentation
  • Berry the Bomb πŸ’£ will be hanging around anywhere you need to blow stuff up (delete code)
  • Peter the Product Manager πŸ‘¨β€πŸ’Ό helps us know what our users want
  • Alfred the Alert 🚨 will occasionally show up in the test failures with potential explanations for why the tests are failing.

Contributors

Thanks goes to these wonderful people (emoji key):

Kent C. Dodds
Kent C. Dodds

πŸ’» πŸ“– πŸš‡ ⚠️
Gautam Pahuja
Gautam Pahuja

⚠️
pom421
pom421

πŸ“–
Marco Moretti
Marco Moretti

πŸ’»
Pritam Sangani
Pritam Sangani

πŸ’»
Emmanouil Zoumpoulakis
Emmanouil Zoumpoulakis

πŸ“–
Peter HozΓ‘k
Peter HozΓ‘k

πŸ’»
Christian Schurr
Christian Schurr

πŸ’» πŸ“–
Dan Schwartz
Dan Schwartz

πŸ“–
William BEUIL
William BEUIL

πŸ“–
Vasilii Kovalev
Vasilii Kovalev

πŸ›
Robbert Wolfs
Robbert Wolfs

πŸ›
Peramanathan Sathyamoorthy
Peramanathan Sathyamoorthy

⚠️ πŸ’»
MichaΓ«l De Boey
MichaΓ«l De Boey

πŸ’»
Bart Wijnants
Bart Wijnants

πŸ“–
Dale Seo
Dale Seo

πŸ’» πŸ“–
Ryan Boone
Ryan Boone

πŸ“–
Bob Owen
Bob Owen

πŸ’» πŸ“–
alberto
alberto

πŸ“–
Mario Sannum
Mario Sannum

πŸ’»
Som Shekhar Mukherjee
Som Shekhar Mukherjee

πŸ’»
Sushil Kumar
Sushil Kumar

πŸ’»
JoΓ£o Pina Fernandes
JoΓ£o Pina Fernandes

πŸ“–
Josh
Josh

πŸ“–
Pawan Kumar
Pawan Kumar

πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

Workshop Feedback

Each exercise has an Elaboration and Feedback link. Please fill that out after the exercise and instruction.

At the end of the workshop, please go to this URL to give overall feedback. Thank you! https://kcd.im/tra-ws-feedback

testing-react-apps's People

Contributors

alberto avatar allcontributors[bot] avatar aprillion avatar bartw avatar creador-dev avatar daleseo avatar emzoumpo avatar falldowngoboone avatar gautam-pahuja avatar jacobparis avatar joao-pina-fernandes avatar joonmo-you avatar joshjm avatar kentcdodds avatar marcosvega91 avatar marioleed avatar michaeldeboey avatar milamer avatar onetruebob avatar p10ns11y avatar pom421 avatar pritamsangani avatar skgyan avatar ssmkhrj avatar tiodan81 avatar wbeuil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

testing-react-apps's Issues

The repository described in Setup section seems to be wrong

Hi Ken,

In the Setup section you say that the repository is https://github.com/kentcdodds/testing-react-app.git
Did you mean https://github.com/kentcdodds/testing-react-apps.git (-apps not -app)?
Also you mention cd bookshelf, but I think that the Setup section refers to something else.
I just want to make sure that I have cloned the correct repository.

Thank you in advance!

Overrides don't work the same with test-data-bot as previous extra credit

In exercise 4 extra credit 3, we allowed overrides for our object factory.

In extra credit 4, no mention is made of the fact that the overrides have to be passed differently. The video makes it sound like you can just do it in the same way, but that doesn't work.

In extra credit 3, we can call buildLoginForm({username: 'chucknorris'}), but in extra credit 4 it needs to be buildLoginForm({overrides: {username: 'test'}}).

This threw me for a loop until I looked back at the docs for test-data-bot. I feel like this should have been called out somewhere.

Error when npm start

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/opt/homebrew/Cellar/node@12/12.22.4/bin/node',
1 verbose cli   '/opt/homebrew/bin/npm',
1 verbose cli   'start'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~start: PATH: /opt/homebrew/Cellar/node@12/12.22.4/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/theo/Desktop/testing-react-apps/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/opt/homebrew/sbin
9 verbose lifecycle [email protected]~start: CWD: /Users/theo/Desktop/testing-react-apps
10 silly lifecycle [email protected]~start: Args: [ '-c', 'react-scripts start' ]
11 silly lifecycle [email protected]~start: Returned: code: 1  signal: null
12 info lifecycle [email protected]~start: Failed to exec start script
13 verbose stack Error: [email protected] start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/opt/homebrew/Cellar/node@12/12.22.4/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:314:20)
13 verbose stack     at ChildProcess.<anonymous> (/opt/homebrew/Cellar/node@12/12.22.4/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:314:20)
13 verbose stack     at maybeClose (internal/child_process.js:1022:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/theo/Desktop/testing-react-apps
16 verbose Darwin 20.6.0
17 verbose argv "/opt/homebrew/Cellar/node@12/12.22.4/bin/node" "/opt/homebrew/bin/npm" "start"
18 verbose node v12.22.4
19 verbose npm  v6.14.14
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] start: `react-scripts start`
22 error Exit status 1
23 error Failed at the [email protected] start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Changelog

Here's what's going to be different in the next version of the testing-react-apps workshop (you can find all these changes in the next branch until the videos are re-recorded):

  • Everything is TypeScript. There's a new script you can run to remove the TypeScript automatically if you want: ./scripts/remove-ts.
  • General improvements to the workshop content based on feedback from learners
  • Exercises 1, 3, 4, 6, and 8 all had instruction improvements based on feedback
  • Exercise 6 (mocking) swapped the extra credits to make it iterate a little bit better.

setup fails

Hello!

Windows Home latest with WSL2,
recently updated repository.
When working locally, npm test - works, yet npm start - fails.
Then I tried docker:
/testing-react-apps$ docker-compose up

till here all is good

#9 13.04 ▢️ Starting: Dependency Installation
#9 13.04 Installing third party code dependencies so the workshop works properly on this computer.
#9 13.05 Running the following command: npm install --legacy-peer-deps --no-save

#9 85.22 npm ERR! code ENOENT
#9 85.22 npm ERR! syscall chmod
#9 85.22 npm ERR! path /app/node_modules/@babel/helper-compilation-targets/node_modules/semver/bin/semver
#9 85.22 npm ERR! errno -2
#9 85.22 npm ERR! enoent ENOENT: no such file or directory, chmod '/app/node_modules/@babel/helper-compilation-targets/node_modules/semver/bin/semver'
#9 85.22 npm ERR! enoent This is related to npm not being able to find a file.
#9 85.22 npm ERR! enoent
#9 85.40
#9 85.40 npm ERR! A complete log of this run can be found in:
#9 85.40 npm ERR! /root/.npm/_logs/2021-06-04T11_55_47_968Z-debug.log
#9 85.42 🚨 Failure: Dependency Installation. Please review the messages above for information on how to troubleshoot and resolve this issue.
#9 85.42 npm notice
#9 85.42 npm notice New minor version of npm available! 7.15.1 -> 7.16.0
#9 85.42 npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.16.0
#9 85.42 npm notice Run npm install -g [email protected] to update!
#9 85.42 npm notice

executor failed running [/bin/sh -c NO_EMAIL_AUTOFILL=true node setup]: exit code: 254
ERROR: Service 'node' failed to build : Build failed

Obsolete information about `jest.config.js`

In Context and Custom Render Method, App Test Utils, Extra Credit Solution 3 video and here there are some references to jest.config.js and whatwg-fetch package.

Because window.fetch isn't supported in JSDOM/Node, we have installed the whatwg-fetch module which will polyfill fetch in our testing environment which will allow MSW to handle those requests for us. This is setup automatically in our jest.config.js file.

As I can see, there is no jest.config.js file in the project. I suppose it was replaced by src/setupTests.js. And whatwg-fetch exists only in package-lock.json (as a react-app-polyfill's dependency), so we can hardly say that "we have installed" the module.

Maybe this paragraph should be removed or at least re-written/updated.

JS file extension references in markdown instructions

Working with instructions in the next TS branch, I notice a few places in 05.md, 06.md, and 07.md which mention JS file extensions:
search for .js\b

The test/server-handlers.js mentioned in 05.md extra credit 1 is an instruction for importing - to my surprise the import works even with .js extension even though only .ts file exists in that directory πŸ€·β€β™‚οΈ so maybe no action needed, up to you.

Exercice 6: use waitForElementToBeRemoved instead of manual await

This is a follow-up after a discussion on Discord.

In exercice 6, we need to use act(). When doing the exercice, I used waitForElementToBeRemoved(). Isn't this better than manually awaiting for the promise? Maybe, waiting for the promise in this lesson was for introducing when/how to use act() ?
image

If you change it, it might also impact the "extra credit 1" as there is no promise there and act is used.

Error running `npm install`

My environment: elementary OS Juno 64-bit (based on Ubuntu LTS 18.04)

➜  react-testing-workshop git:(master) node --version
v11.13.0
➜  react-testing-workshop git:(master) npm --version
6.7.0

Error message

➜  react-testing-workshop git:(master) sudo npm install

> [email protected] preinstall /home/andy/Workshops/react-testing-workshop/node_modules/node
> node installArchSpecificPackage

Unhandled rejection Error: EACCES: permission denied, open '/home/andy/.npm/_cacache/tmp/df60ebfc'

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/andy/.npm/_logs/2019-04-09T15_15_12_096Z-debug.log
module.js:549
    throw err;
    ^

Error: Cannot find module 'node-linux-x64/package.json'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.resolve (internal/module.js:18:19)
    at ChildProcess.<anonymous> (/home/andy/Workshops/react-testing-workshop/node_modules/node-bin-setup/index.js:18:27)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
npm WARN [email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/react-scripts/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] preinstall: `node installArchSpecificPackage`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/andy/.npm/_logs/2019-04-09T15_15_13_100Z-debug.log

Cannot render Counter with createRoot

Using the new createRoot syntax I cannot see the Counter component (or anything else I try to render).

My code:

  act(() => {
    const div = document.createElement('div')
    document.body.append(div)
    createRoot(div).render(<Counter />)
  })

Output of console.log(document.body.innerHtml) is <div><div>

[Exercise - 6] Have a different test for checking spinner

Hi
I was working through this workshop and stumbled on exercise 6.

Checking the position, as well as the spinner in the same test, is leading it to be convoluted. Splitting it into two simplifies a lot of stuff.

My suggestion is to have a different test for checking the "loading" state.

Excercise 05 is using msw 1.0 (rest). I think we should update to 2.0 (http)

I am following the tutorials so I don't know if this impacts other exercises.

Why should we update ?

  • if you use msw documentation, it uses http API instead of rest. Changes in the API are not big, but this might cause some trouble for someone (it kind of did to me because I was searching in the docs using "rest" as a keyword and I was encountering the "HTTP" API instead).
  • to keep the course up to date

Problems with the update:

  • Changing rest with HTTP directly might require a video update, not only a PR in the repo

I suggest, until the video update, to leave a comment and/or an extra credit telling students about msw update: https://mswjs.io/docs/migrations/1.x-to-2.x
https://mswjs.io/blog/introducing-msw-2.0

I can open a PR if this sounds ok.

needed packages

Hi Ken,

Just to let you know, I needed to install the packages replace-in-fileand is-ci before I could run the npm setup. There probaly in your global npm repository.

Cya Thursday @ the workshop.

Exercise 01 is updated to React 18 but lacks instructions

Exercise 01.js is updated to React 18. However 01.md lacks the instructions for new to testing on how to create root element, how to use createRoot() and does not mention act() which is used in the solution (with the exception to the link about configuration).

The video on epicreact.dev uses previous React version and instructions there are outdated.

Exercise 5.extra-3: toMatchInlineSnapshot causes JSX parsing error

The 3rd extra credit for exercise 5 suggests using inline snapshot testing to avoid manually copying error messages.

However, calling toMatchInlineSnapshot() causes the test to error with the following message:

SyntaxError: <path-to>/testing-react-apps/src/__tests__/exercise/05.js: Support for the experimental syntax 'jsx' isn't currently enabled (33:10):

      31 |
      32 | test(`logging in displays the user's username`, async () => {
    > 33 |   render(<Login />)
         |          ^
      34 |   const { username, password } = buildLoginForm()
      35 |
      36 |   await userEvent.type(screen.getByLabelText(/username/i), username)

Add @babel/preset-react (https://github.com/babel/babel/tree/main/packages/babel-preset-react) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-jsx) to the 'plugins' section to enable parsing.

This appears to be related to the recent update to react-scripts 5 as suggested by this issue:
facebook/create-react-app#11928

This can be worked around by using toMatchSnapshot()

Error running tests

When cloning and using node setup an error happens when trying to start the tests.

Error message when running npm t

$ npm t

> [email protected] test MY_DIRECTORY\epic-react\testing-react-apps
> react-scripts test

Error: Failed to initialize watch plugin "node_modules/jest-watch-typeahead/filename.js":

  ● Test suite failed to run

    file:///MY_DIRECTORY/epic-react/testing-react-apps/node_modules/jest-watch-typeahead/build/file_name_plugin/prompt.js:4
    import { PatternPrompt, printPatternCaret, printRestoredPatternCaret } from 'jest-watcher';
                            ^^^^^^^^^^^^^^^^^
    SyntaxError: Named export 'printPatternCaret' not found. The requested module 'jest-watcher' is a CommonJS module, which may not support all module.exports as named exports.
    CommonJS modules can always be imported via the default export, for example using:

    import pkg from 'jest-watcher';
    const { PatternPrompt, printPatternCaret, printRestoredPatternCaret } = pkg;

      at async requireOrImportModule (node_modules/jest-util/build/requireOrImportModule.js:65:32)
      at async watch (node_modules/@jest/core/build/watch.js:337:34)
      at async _run10000 (node_modules/@jest/core/build/cli/index.js:311:7)
      at async runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

npm ERR! Test failed.  See above for more details.

Setup message

$ node setup
▢️  Starting workshop setup...
      Running the following command: npx "https://gist.github.com/kentcdodds/bb452ffe53a5caa3600197e1d8005733" -q
npx: installed 1 in 6.363s
    ▢️  Starting: System Validation
          Ensuring the correct versions of tools are installed on this computer.
          Running the following command: npx "https://gist.github.com/kentcdoddsabbc32701f78fa70298d444c2303b6d9"
npx: installed 2 in 4.061s
    βœ…  Success: System Validation


    ▢️  Starting: Dependency Installation
          Installing third party code dependencies so the workshop works properly on this computer.
          Running the following command: npm install --legacy-peer-deps --no-save
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my
best with it!

> [email protected] install MY_DIRECTORY\epic-react\testing-react-apps\node_modules\husky
> node husky install

husky > Setting up git hooks
husky > Done

> [email protected] postinstall MY_DIRECTORY\epic-react\testing-react-apps\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js:
> https://opencollective.com/core-js
> https://patreon.com/zloirock
> bitcoin: bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz

Also, the author of core-js ( https://github.com/zloirock ) is looking for a goo
d job -)


> [email protected] postinstall MY_DIRECTORY\epic-react\testing-react-apps\node_modules\core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"


> [email protected] postinstall MY_DIRECTORY\epic-react\testing-react-apps\node_modules\hus
ky
> opencollective-postinstall || exit 0

Thank you for using husky!
If you rely on this package, please consider supporting our open collective:
> https://opencollective.com/husky/donate


> [email protected] postinstall MY_DIRECTORY\epic-react\testing-react-apps\node_modules\msw
> node -e "try{require('./config/scripts/postinstall')}catch(e){}"

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fse
vents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)

added 1401 packages from 770 contributors and audited 1405 packages in 125.236s

198 packages are looking for funding
  run `npm fund` for details

found 1 high severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details
    βœ…  Success: Dependency Installation


    ▢️  Starting: Project Validation
          Running validation checks to ensure dependencies were installed properly
          Running the following command: npm run validate -s

 RUNS  src/__tests__/final/05.extra-4.js
 PASS  src/__tests__/final/06.extra-2.js (5.714 s)
 PASS  src/__tests__/exercise/06.js
 PASS  src/__tests__/exercise/05.js (16.289 s)
 PASS  src/__tests__/exercise/02.js
 PASS  src/__tests__/final/05.js (17.162 s)
 PASS  src/__tests__/final/05.extra-1.js (17.21 s)
 PASS  src/__tests__/final/05.extra-3.js (17.648 s)
 PASS  src/__tests__/final/05.extra-2.js (17.596 s)
 PASS  src/__tests__/final/05.extra-4.js (18.525 s)
 PASS  src/__tests__/final/04.extra-3.js (11.293 s)
 PASS  src/__tests__/final/08.extra-3.js
 PASS  src/__tests__/final/03.extra-1.js
 PASS  src/__tests__/final/04.js
 PASS  src/__tests__/final/07.extra-2.js
 PASS  src/__tests__/final/04.extra-1.js
 PASS  src/__tests__/final/07.extra-3.js
 PASS  src/__tests__/final/06.js
 PASS  src/__tests__/final/03.js
 PASS  src/__tests__/final/07.extra-1.js
 PASS  src/__tests__/final/04.extra-4.js
 PASS  src/__tests__/final/08.extra-2.js
 PASS  src/__tests__/final/08.js
 PASS  src/__tests__/final/04.extra-2.js
 PASS  src/__tests__/exercise/04.js
 PASS  src/__tests__/exercise/08.js
 PASS  src/__tests__/exercise/03.js
 PASS  src/__tests__/final/06.extra-1.js
 PASS  src/__tests__/final/07.js
 PASS  src/__tests__/final/02.js
 PASS  src/__tests__/final/01.extra-1.js
 PASS  src/__tests__/final/01.js
 PASS  src/__tests__/exercise/01.js
 PASS  src/__tests__/final/02.extra-1.js
 PASS  src/__tests__/exercise/07.js
 PASS  src/__tests__/final/08.extra-1.js

Test Suites: 35 passed, 35 total
Tests:       48 passed, 48 total
Snapshots:   2 passed, 2 total
Time:        29.204 s
Ran all test suites.
Compiled successfully.

File sizes after gzip:

  105.46 kB  build\static\js\main.266a9c8b.js
  1.21 kB    build\static\js\878.e924fdb4.chunk.js
  978 B      build\static\js\304.7048674c.chunk.js
  928 B      build\static\js\704.0807f0c9.chunk.js
  467 B      build\static\js\456.dd9828aa.chunk.js
  442 B      build\static\js\400.860bd762.chunk.js
  354 B      build\static\js\48.e96fc3b5.chunk.js
  312 B      build\static\css\main.98c25710.css

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

  npm install -g serve
  serve -s build

Find out more about deployment here:

  https://cra.link/deployment

    βœ…  Success: Project Validation


    ▢️  Starting: Autofilling Email
          Each exercise comes with a elaboration form to help your retention. Pr
oviding your email now will mean you don't have to provide it each time you fill
 out the form.
          Running the following command: npx "https://gist.github.com/kentcdodds
/2d44448a8997b9964b1be44cd294d1f5"
npx: installed 86 in 28.717s
? What's your email address? MY_EMAIL
Updated 8 files with the email MY_EMAIL
Committing changes for you so your jest watch mode works nicely
[main afee034] email autofill
 8 files changed, 8 insertions(+), 8 deletions(-)
    βœ…  Success: Autofilling Email


βœ…  Workshop setup complete...

Mocking HTTP Requests: missing instructions for "Mocked Responses Solution 2" video?

Are the instructions for the "Mocked Responses Solution 2" video missing in the 05.md file?

I got a bit confused because after doing the "Exercise", which I assume corresponds to the "Mock Service Worker Solution 1" video.. I went directly to do the first extra credit "reuse server request handlers", which corresponds to the third solution video instead.

Screenshot 2024-01-30 at 16 48 50 Screenshot 2024-01-30 at 16 47 57

Exercise 03 - Trigger click event using userEvent doesn't work

After I check the video of the solution for the extra credit for exercise 03, I found that the unit tests fail. After a little research on StackOverflow I found this answer and I checked the code and
image

After I compare it with fireEvent, I can say that the problem is that userEvent.click returns a promise. The click event is not executed. You need to wait until the promise is executed before assert

After you add await the test works well and passes it

Incorrect titles and videos in 'Form Testing' section

How the playlist looks like:
image

How the markdown section titles look like:
image
image
image

"Abstract Variables" video is absolutely the same as "Jest Mock Functions" with different placeholders, "Jest Mock" shouldn't be Solution since it is in Extra Credit-s, the videos order is incorrect.

So, something is wrong with this exercise from videos and/or docs perspective.
@kentcdodds

Why promise is needed in exercise 6?

window.navigator.geolocation.getCurrentPosition.mockImplementation(

Hi Kent,

I don't understand why the promise is needed for the 6th exercise.

Won't this be enough ?

      window.navigator.geolocation.getCurrentPosition = jest.fn().mockImplementation(
              (success, error) => success(fakePosition))

Or maybe are you trying to introduce some async work to be closer to reality?

Mocking Browser APIs and Modules Inconsistency

In the video solution, the test execution for this module passed despite the error (and correctly updated the UI when running screen.debug()) before wrapping the execution of the resolve and promise in act(), however my test was actually failing here (and the screen.debug() still showed the loading spinner) until wrapping those actions in act(). Just a not in case you wanted to update the comments/video because I was confused where my inconsistencies were coming from. I spent quite a bit of time trying to find the issue and all I had to do was add act(), though I'm still not sure why they behave differently.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.