From 7ce243873e2ac349fde2e09eb17d54fc695bd289 Mon Sep 17 00:00:00 2001 From: David Johnston Date: Fri, 30 Aug 2024 17:27:51 +1000 Subject: [PATCH 1/5] Update example-intro.mdx Updates the example notes re: MSW to mention that jsdom doesn't include fetch and will require a polyfill --- docs/react-testing-library/example-intro.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/react-testing-library/example-intro.mdx b/docs/react-testing-library/example-intro.mdx index a5d67830f..dd7f60011 100644 --- a/docs/react-testing-library/example-intro.mdx +++ b/docs/react-testing-library/example-intro.mdx @@ -72,6 +72,8 @@ We recommend using the declaratively mock API communication in your tests instead of stubbing `window.fetch`, or relying on third-party adapters. +Our example here uses axios to make its API calls. If your application uses [`fetch()`][https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch] to make its API calls, then be aware that by default JSDOM does not include fetch. If you are using vitest as your test runner, it will be included for you. For jest you may wish to manually polyfill `fetch()` or use the [jest-fixed-jsdom](https://github.com/mswjs/jest-fixed-jsdom) environment which includes fetch. + ::: ```jsx title="__tests__/fetch.test.jsx" From 69b1122367e8c5d84448d9d48702a8c001638bbd Mon Sep 17 00:00:00 2001 From: David Johnston Date: Thu, 5 Sep 2024 16:55:47 +1000 Subject: [PATCH 2/5] Fix link --- docs/react-testing-library/example-intro.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/react-testing-library/example-intro.mdx b/docs/react-testing-library/example-intro.mdx index dd7f60011..c771e1c39 100644 --- a/docs/react-testing-library/example-intro.mdx +++ b/docs/react-testing-library/example-intro.mdx @@ -72,7 +72,7 @@ We recommend using the declaratively mock API communication in your tests instead of stubbing `window.fetch`, or relying on third-party adapters. -Our example here uses axios to make its API calls. If your application uses [`fetch()`][https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch] to make its API calls, then be aware that by default JSDOM does not include fetch. If you are using vitest as your test runner, it will be included for you. For jest you may wish to manually polyfill `fetch()` or use the [jest-fixed-jsdom](https://github.com/mswjs/jest-fixed-jsdom) environment which includes fetch. +Our example here uses axios to make its API calls. If your application uses [`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch) to make its API calls, then be aware that by default JSDOM does not include fetch. If you are using vitest as your test runner, it will be included for you. For jest you may wish to manually polyfill `fetch()` or use the [jest-fixed-jsdom](https://github.com/mswjs/jest-fixed-jsdom) environment which includes fetch. ::: From 8c5077170935485077dbf7422ab8844e4210994d Mon Sep 17 00:00:00 2001 From: David Johnston Date: Thu, 7 Nov 2024 15:37:52 +1100 Subject: [PATCH 3/5] Update example-intro.mdx --- docs/react-testing-library/example-intro.mdx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/react-testing-library/example-intro.mdx b/docs/react-testing-library/example-intro.mdx index c771e1c39..e5da1579e 100644 --- a/docs/react-testing-library/example-intro.mdx +++ b/docs/react-testing-library/example-intro.mdx @@ -71,6 +71,9 @@ We recommend using the [Mock Service Worker (MSW)](https://github.com/mswjs/msw) library to declaratively mock API communication in your tests instead of stubbing `window.fetch`, or relying on third-party adapters. +::: + +:::note Our example here uses axios to make its API calls. If your application uses [`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch) to make its API calls, then be aware that by default JSDOM does not include fetch. If you are using vitest as your test runner, it will be included for you. For jest you may wish to manually polyfill `fetch()` or use the [jest-fixed-jsdom](https://github.com/mswjs/jest-fixed-jsdom) environment which includes fetch. From 4a65b6d12c9af721a31fe63b3e485df235297798 Mon Sep 17 00:00:00 2001 From: David Johnston Date: Thu, 7 Nov 2024 16:03:32 +1100 Subject: [PATCH 4/5] Update example-intro.mdx --- docs/react-testing-library/example-intro.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/react-testing-library/example-intro.mdx b/docs/react-testing-library/example-intro.mdx index e5da1579e..15e8dd368 100644 --- a/docs/react-testing-library/example-intro.mdx +++ b/docs/react-testing-library/example-intro.mdx @@ -76,7 +76,6 @@ declaratively mock API communication in your tests instead of stubbing :::note Our example here uses axios to make its API calls. If your application uses [`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch) to make its API calls, then be aware that by default JSDOM does not include fetch. If you are using vitest as your test runner, it will be included for you. For jest you may wish to manually polyfill `fetch()` or use the [jest-fixed-jsdom](https://github.com/mswjs/jest-fixed-jsdom) environment which includes fetch. - ::: ```jsx title="__tests__/fetch.test.jsx" From 13f160b2d5c7f2eaaa0ca4a3e5a3e7915ed791e6 Mon Sep 17 00:00:00 2001 From: David Johnston Date: Thu, 7 Nov 2024 16:04:48 +1100 Subject: [PATCH 5/5] Update example-intro.mdx --- docs/react-testing-library/example-intro.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/react-testing-library/example-intro.mdx b/docs/react-testing-library/example-intro.mdx index 15e8dd368..66722d223 100644 --- a/docs/react-testing-library/example-intro.mdx +++ b/docs/react-testing-library/example-intro.mdx @@ -71,11 +71,13 @@ We recommend using the [Mock Service Worker (MSW)](https://github.com/mswjs/msw) library to declaratively mock API communication in your tests instead of stubbing `window.fetch`, or relying on third-party adapters. + ::: :::note Our example here uses axios to make its API calls. If your application uses [`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch) to make its API calls, then be aware that by default JSDOM does not include fetch. If you are using vitest as your test runner, it will be included for you. For jest you may wish to manually polyfill `fetch()` or use the [jest-fixed-jsdom](https://github.com/mswjs/jest-fixed-jsdom) environment which includes fetch. + ::: ```jsx title="__tests__/fetch.test.jsx"