S
S
shittyColMajorXform2020-07-21 20:50:56
JavaScript
shittyColMajorXform, 2020-07-21 20:50:56

How to get around issues with arrow functions in store class for jest testing?

Hello. I'm setting up jest and there's a problem with arrow functions in stores.
It's in the jest documentation

Please note that if you use arrow functions in your classes, they will not be part of the mock. The reason for that is that arrow functions are not present on the object's prototype, they are merely properties holding a reference to a function.


I tried to set up babel to convert arrow functions
module.exports = {
  presets: [
    [
      "@babel/preset-env",
      {
        targets: {
          node: "current"
        }
      }
    ],
    "module:metro-react-native-babel-preset"
  ],
  plugins: [
    ["@babel/plugin-transform-arrow-functions", { spec: true }],
    [
      "@babel/plugin-proposal-decorators",
      {
        legacy: true
      }
    ]
  ]
};


however, it did not give any result.

Can anyone suggest ways to solve this problem without manually redefining functions in mocks?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question