dialogflow-javascript-client icon indicating copy to clipboard operation
dialogflow-javascript-client copied to clipboard

Testing with jest causes Syntax error on "export" at api-ai-javascript/index.js:1

Open dtodo1paco opened this issue 6 years ago • 2 comments

Hi! I'm working in a React application which uses api-ai-client to integrate dialogflow features. Everything works as espected when I manually test the application, but when I try to create some automated tests (with jest), I get the following error, just trying to render the component (which includes api-ai-client)

 FAIL  __tests__/unit/App.test.js
  ● Test suite failed to run

    /BAR/WORKSPACE/TMP/react-api-ai-poc/node_modules/api-ai-javascript/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from "./es6/ApiAiClient";
                                                                                             ^^^^^^
    SyntaxError: Unexpected token export

      4 | const doSendMessage = async (message, token) => {
      5 |     let ret = null;
    > 6 |     try {
      8 |         const client = new ApiAiClient({accessToken: token});

Can anybody please tell me the steps to integrate this api (and to mock it if possible) ?

// .babelrc

{
  "presets": [
    "env",
    "react",
    "latest",
    "stage-2"
  ],
  "plugins": ["transform-remove-strict-mode"]

}

Also tried in jest.config

transform: {
        "^.+\\.jsx?$": "babel-jest"
 },

Regards,

dtodo1paco avatar Aug 03 '18 17:08 dtodo1paco

Hey, did you get an solution to this issue?

lnm8910 avatar Nov 18 '19 20:11 lnm8910

Yes, you can take a look here

dtodo1paco avatar Nov 22 '19 15:11 dtodo1paco