These mocks must be the first thing imported in the test file or else they won't be in place when the test imports the actual component.
If we don't import anything from the mocks file, then eslint is perfectly happy with the mock import being first. However, as in the example above, we might want to import useRouter so that we can change its return value in different tests. If we do, then eslint will warn that the import order is incorrect.
This PR fixes that issue by adding a pathGroups entry that captures ./*.test.mocks imports and requires them to be before builtin, which is the first item in our groups property.
In our unit tests, we often have a
*.test.mocks
file containing the mocking that we're doing for a test. For example, we might do this:These mocks must be the first thing imported in the test file or else they won't be in place when the test imports the actual component.
If we don't import anything from the mocks file, then eslint is perfectly happy with the mock import being first. However, as in the example above, we might want to import
useRouter
so that we can change its return value in different tests. If we do, then eslint will warn that the import order is incorrect.This PR fixes that issue by adding a
pathGroups
entry that captures./*.test.mocks
imports and requires them to be beforebuiltin
, which is the first item in ourgroups
property.