reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.71k stars 1.17k forks source link

Facing Issue for Test suite failed to run TypeError: (0 , toolkit_1.createSlice) is not a function #2400

Closed rishabh9141 closed 2 years ago

rishabh9141 commented 2 years ago

Hi I am facing attached issue for unit testing.

"react-native": "0.63.3", "@testing-library/jest-native": "^4.0.5", "@testing-library/react-native": "^9.1.0", "@reduxjs/toolkit": "^1.4.0",

import {createSlice} from '@reduxjs/toolkit';
import {SidebarState} from './type';
import {SIDEBAR_STATE} from '@moxie/constants';

export const initialSidebarState: SidebarState = {
  leftSidebarOpen: false,
  rightSidebarOpen: false,
  settingsOpen: false,
};

export const {actions: sidebarActions, reducer: sidebarReducer} = createSlice({
  name: SIDEBAR_STATE,
  initialState: initialSidebarState,
  reducers: {
    closeDrawer(state: any) {
      state.leftSidebarOpen = false;
      state.rightSidebarOpen = false;
    },
    toggleLeftDrawer(state: any) {
      state.leftSidebarOpen = !state.leftSidebarOpen;
      state.rightSidebarOpen = false;
    },
    toggleRightDrawer(state: any) {
      state.rightSidebarOpen = !state.rightSidebarOpen;
      state.leftSidebarOpen = false;
    },
  },
});

jest Config

module.exports = {
  preset: 'react-native',
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
  setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
  transform: {
    '^.+\\.(js)$': 'babel-jest',
    '\\.(ts|tsx)$': 'ts-jest',
  },
  transformIgnorePatterns: [
    '/node_modules/(?!react-native).+\\.js$',
  ],
  cacheDirectory: './cache',
  coveragePathIgnorePatterns: ['./app/utils/vendor'],
  coverageThreshold: {
    global: {
      statements: 80,
    },
  },
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
  setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
  moduleNameMapper: {
    '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$/':
      '<rootDir>/__mocks__/fileMock.js',
    '\\.(css|less|scss)$': '<rootDir>/__mocks__/styleMock.js',
    "@moxie/core-ui": "<rootDir>/src/core-ui",
    "@moxie/assets/(.*)": "<rootDir>/src/assets/$1",
    "@moxie/hooks": "<rootDir>/src/hooks",
    "@moxie/components": "<rootDir>/src/components",
    "@moxie/fixtures": "<rootDir>/src/fixtures",
    "@moxie/constants": "<rootDir>/src/constants",
    "@moxie/screens": "<rootDir>/src/screens",
    "@moxie/redux": "<rootDir>/src/redux",
    "@moxie/services": "<rootDir>/src/services",
    "@moxie/navigation": "<rootDir>/src/navigation",
    "@moxie/config": "<rootDir>/src/config",
    "@moxie/helpers": "<rootDir>/src/helpers",
    "redux": "<rootDir>/node_modules/redux"
  },
};
Screenshot 2022-06-10 at 2 17 43 PM
phryneas commented 2 years ago

Seems like a transpilation issue - your jest is not set up correctly to work with your node_modules.

rishabh9141 commented 2 years ago

@phryneas I have updated jest set up. Please check

phryneas commented 2 years ago

This is the Redux Toolkit issue tracker. It's a place where you can report bugs in Redux Toolkit, or feature requests. But it's really not a place where we can help you debug your jest setup, i'm sorry. Please ask on StackOverflow or in the jest channel on Reactiflux