0

Hello how can I use ES6 with Jest. Because they send me a mistake in spread (operator) and export. How to modify jest?

export default function reducer(state={
    open:false
  }, action) {

    switch (action.type) {
      case "HANDLE_TAP_HOME": {
        return {...state,open:action.open}
        
      }
    }

    return state
}

test

import base from '../../client/src/redux/reducer/reducers/Admin/base/Index'

describe('request to Reducer',()=>{
    it('fetch',()=>{
        expect(base(undefiend,{type:'nothing'})).toEqual({
            open:false
        })
    })
})

5
  • There is no spread operator in the code you've posted. Commented Aug 12, 2017 at 0:47
  • What is the error you are getting here? Commented Aug 12, 2017 at 1:50
  • Unexpected token import Commented Aug 12, 2017 at 7:15
  • Have a look at my answer here: Unexpected import token - testing React Native with Jest Commented Aug 12, 2017 at 7:19
  • Yes, using the spread syntax with objects in ES6 is a mistake. Commented Aug 12, 2017 at 7:53

1 Answer 1

1

jest configuration file

"jest": {
    "scriptPreprocessor": "<rootDir>/node_modules/jest-babel-preprocessor/preprocessor.js",
    "unmockedModulePathPatterns": [
      "<rootDir>/node_modules/react"
    ]
  }

dependencies

npm i --D jest-cli jest-babel-preprocessor

bye

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.