stryker-mutator / stryker-js

Mutation testing for JavaScript and friends
https://stryker-mutator.io
Apache License 2.0
2.56k stars 241 forks source link

Cannot mutation test the call of a redux reducer (Typescript) #3912

Open magwas opened 1 year ago

magwas commented 1 year ago

I am trying to set up mutation testing for a project using react, redux and typescript

The tests run fine with jest. The stryker dry run fails due to

undefinedtests/com.kodekonveyor.reacttest.ui/registerPerson.test.ts:25:51 - error TS2349: This expression is not callable.
  Not all constituents of type 'void | ActionCreatorWithOptionalPayload<Person, "/addPerson" | "testApp/addPerson">' are callable.
 Type 'void' has no call signatures.

  expect(dispatch).toHaveBeenCalledWith(actions.addPerson(formState))

actions.addPerson is defined by the following code:

const appState = createSlice({
  name: 'testApp',
  initialState: initialState,
  reducers: {
    addPerson: addPerson
  },
})
export const actions = appState.actions

You can find the code at commit 7fdc9e330cd3fcb12fab90711504608cdca00eda of https://github.com/magwas/reacttest

It is small experimental code, not much more than needed to reproduce the error.

Stryker config

{
  "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
  "packageManager": "npm",
  "reporters": [
    "html",
    "clear-text",
    "progress"
  ],
  "testRunner": "jest",
  "coverageAnalysis": "perTest"
}
}

Test runner config

jest.config.js ''' /* @type {import('ts-jest').JestConfigWithTsJest} / module.exports = { preset: 'ts-jest', testEnvironment: 'node', }; '''

Stryker environment

├── @stryker-mutator/core@6.3.1
├── @stryker-mutator/jest-runner@6.3.1
├── @stryker-mutator/jest-runner@6.3.1
├── @types/jest@29.2.4
├── babel-jest@29.3.1
├── jest-mock-extended@3.0.1
├── jest@29.3.1
├── ts-jest@29.0.3

Test runner environment

$ npm run test

> reacttest@0.1.0 test
> jest

 PASS  tests/com.kodekonveyor.reacttest.ui/registerPerson.test.ts
  registerPerson
    ✓ prevents automatic redraw of the form (2 ms)
    ✓ adds the person from the form to the person list (1 ms)
    ✓ reinitializes the form data

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        2.486 s, estimated 5 s
Ran all test suites.

Your Environment

software version(s)
node v19.2.0
npm 8.19.3
Operating System Ubuntu jammy

Add stryker.log

magwas commented 1 year ago

stryker.log

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.