From 7117a3555e2be9e9438428805d6f16217edb3f92 Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Fri, 6 Jun 2025 11:48:31 -0400 Subject: [PATCH] update part6a.md add: instructions to configure `jest` globals for vite: ^6.3.5 the existing notes pre-suppose that a file `.eslintrc.cjs` exists, which doesn't come with newer versions of vite. these changes guide students using a newer version of vite to configure their project so jest globals (describe, test, etc.) can be used without importing. thanks! :) --- src/content/6/en/part6a.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/content/6/en/part6a.md b/src/content/6/en/part6a.md index 8be68fcaff1..1602701eb7c 100644 --- a/src/content/6/en/part6a.md +++ b/src/content/6/en/part6a.md @@ -418,7 +418,7 @@ Let us expand package.json with a script for running the tests: } ``` -And finally, .eslintrc.cjs needs to be altered as follows: +And finally, we'd like to make the functions from 'jest' available globally. If your directory contains .eslintrc.cjs. it needs to be altered as follows: ```js module.exports = { @@ -432,6 +432,23 @@ module.exports = { } ``` +If you're using a newer version of Vite, modify eslint.config.js as follows: + +```js +export default [ + // ... + { + files: ['**/*.{js,jsx}'], + languageOptions: { + ecmaVersion: 2020, + globals: [...globals.browser, ...globals.jest], // highlight-line + // ... + }, + // ... + }, +] +``` + To make testing easier, we'll first move the reducer's code to its own module, to the file src/reducers/noteReducer.js. We'll also add the library [deep-freeze](https://www.npmjs.com/package/deep-freeze), which can be used to ensure that the reducer has been correctly defined as an immutable function. Let's install the library as a development dependency: