Guide for VFS teams to update tests for Node 22
Last Updated: June 26, 2025
Platform is in the process of upgrading the version of Node used to build vets-website from 14 to 22. This guide is designed to help VFS teams migrate tests to run under Node 22. Many tests will not need updating; but some tests will fail under Node 22 due to changes in Node or other dependencies that have been updated.
Note: All pull requests for this work will need to be merged into the main branch in vets-website
Extension Change:
All unit test specs must end with .jsx in Node 22. Previously, specs could end with .js or .jsx. A linting will enforce this.
Mock Service Worker
To work with Node 22, MSW has been updated to version 2.x and this requires changes to any code that uses MSW:
node 14 | node 22 |
|---|---|
|
|
JS
|
JS
|
JS
|
JS
|
JS
|
JS
|
JS
|
JS
|
window.location
We have moved from using jsdom to happy-dom for Browser simulation and this requires some modifications to tests that access the window.location object.
node 14 | node 22 |
|---|---|
|
|
JS
|
JS
|
|
|
JS
|
JS
|
JS
|
JS
|
Miscellaneous
If your component accesses
sessionStorageorlocalStoragebe sure to usewindow.sessionStorageorwindow.localStoragein the component or else component modifications will not be picked up in a test.If your assertions are failing, try refactoring your test to use
RTLand put the assertions inside awaitFor. For example, consider the following example of updating a test from node 14 to node 22:
node 14 | node 22 |
|---|---|
JS
|
JS
|
In Node 22 the
Responseobject is immutable after creation, whereas this was not the case in Node 14; make sure all options are included in the object at creation time as no error is thrown if you attempt to write to an immutable object (but the write will fail).
node 14 | node 22 |
|---|---|
JS
|
JS
|
JS
Note: the input in this case is of type “number” |
JS
Note: cannot use normal RTL method to set the input’s value because the value here is not of the input’s type. |
Help and feedback
Get help from the Platform Support Team in Slack.
Submit a feature idea to the Platform.