Triggered invalid code smell in Jest for typescript:S6481

Template for a good new topic, formatted with Markdown:

  • ALM used (Azure DevOps)
  • CI system used ( Azure DevOps)
  • Languages of the repository (React)

Triggered: " The array passed as the value prop to the Context provider changes every render. To fix this consider wrapping it in a useMemo hook." for Jest test.

We only could use react hook in function component, so this rule shouldn’t apply to test?

SonarCloud is asking “<StateContext.Provider value={[testState, () => {}]}>” and " <NotificationContext.Provider value={[{}, () => {}]}>" to useMemo hook

Rule: typescript:S6481

Code:

test('open new window when click quote id from exception search result', () => {
  render(
    <Router history={createMemoryHistory()}>
      <StateContext.Provider value={[testState, () => {}]}>
        <NotificationContext.Provider value={[{}, () => {}]}>
The array passed as the value prop to the Context provider changes every render. To fix this consider wrapping it in a useMemo hook.
          <Exceptions />
        </NotificationContext.Provider>
      </StateContext.Provider>
    </Router>
  )
})

Thanks for your help in advance.

Having sonar-project.properties setup as well and this file is added to the sonar.test.inclusion path.
example:

sonar.sources=src
sonar.tests=src
sonar.test.inclusions=**/*.test.tsx
sonar.exclusions=**/*.test.tsx