Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] handleAction throws error in test environment using AVA #245

Open
1 of 2 tasks
Ethella opened this issue Nov 30, 2020 · 0 comments
Open
1 of 2 tasks

[5.1] handleAction throws error in test environment using AVA #245

Ethella opened this issue Nov 30, 2020 · 0 comments

Comments

@Ethella
Copy link

Ethella commented Nov 30, 2020

Description

Mandatory info

  • Are you extending internal types to enable type-free syntax with createReducer?
// If yes PASTE HERE your types.d.ts

How to Reproduce

CodeSandbox Link

(PASTE HERE your codesandbox link)

No CodeSandbox Link

If no codesandbox, then please provide a full working code example below including actions, reducers and your custom types used in the example.

import test from 'ava';
import * as actions from '~/app/store/auth/auth.actions';
import { store } from '~/app/store';

test('initAuthState', async t => {

  await store.dispatch(
   actions.initAuthState()
});
// auth.actions.ts
export const initAuthState = createAction(actionTypes.INIT_AUTH_STATE)();

// reducer.ts
const AuthReducer = createReducer<AuthState, AuthActions>(initialState)
  .handleAction(initAuthState, () => ({ ...initialState }));

Error

  Uncaught exception in test/spec/app/store/auth/auth.actions.spec.ts

  /node_modules/typesafe-actions/src/utils/validation.ts:79

  Error: Argument 1 is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol

  throwInvalidActionTypeOrActionCreator (node_modules/typesafe-actions/src/utils/validation.ts:79:9)
  map (node_modules/typesafe-actions/src/create-reducer.ts:120:15)
  Function.reducerHandler (node_modules/typesafe-actions/src/create-reducer.ts:111:8)
  Object.<anonymous> (src/app/store/auth/auth.reducer.ts:2:2138)
  Module.m._compile (node_modules/ts-node/src/index.ts:858:23)
  module.exports (node_modules/default-require-extensions/js.js:7:9)

Error trace


https://github.com/piotrwitek/typesafe-actions/blob/master/src/create-reducer.ts#L120

Expected behavior

Production seems to be working just fine, but not sure why the error is thrown when creating the reducer in a test environment.

Suggested solution(s)

An example of how to write tests would be helpful.

Project Dependencies

  • Typesafe-Actions Version: ^5.1.0
  • TypeScript Version: ~3.8.3
  • tsconfig.json:
{
  "compilerOptions": {
    "lib": ["esnext"],
    "module": "esnext",
    "moduleResolution": "node",
    "target": "es5",
    "jsx": "react",
    "strict": true,
    "allowSyntheticDefaultImports": true,
    "noImplicitReturns": false,
    "noImplicitThis": true,
    "noImplicitAny": false,
    "esModuleInterop": true,
    "downlevelIteration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "outDir": "../build",
    "baseUrl": "..",
    "paths": {
      "~/*": ["src/*"],
    },
  },

  "include": [
    "../src/**/*.ts",
    "../src/**/*.tsx",
    "../test/**/*.ts",
    "../test/**/*.tsx"
  ],
}

Environment (optional)

  • Browser and Version: XXX
  • OS: XXX
  • Node Version: XXX
  • Package Manager and Version: XXX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant