Friday, 26 May 2017

How to test redux API with node

I am new to both nodejs and redux. I already have node v7.10 installed on my machine. When I read the redux doc, it claims I should be able to test the action, reducer and store API without UI.

So what I want to do is try to test them in a pure nodejs program.

Here are the step, I am trying to do:

  1. create my testing directory for my testing project and run npm init to create a package.json file

  2. run npm install --save redux to get redux module in my testing directory

  3. create a file named reducer.js with the following content:

    import { combineReducers } from 'redux';
    console.log('testing.');
    
    

However, when I try to test my script: node reducer.js, I encountered SyntaxError: Unexpected token import

SyntaxError: Unexpected token import
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)



via bufferoverflow76

No comments:

Post a Comment