kentcdodds / babel-plugin-macros

🎣 Allows you to build simple compile-time libraries
https://npm.im/babel-plugin-macros
MIT License
2.62k stars 135 forks source link

Use virtual mocks instead of fake node modules thing #123

Closed kentcdodds closed 4 years ago

kentcdodds commented 5 years ago

Just dropping a quick note so I don't forget. I'm pretty sure that we can replace this:

https://github.com/kentcdodds/babel-plugin-macros/blob/2d57c60adadd8904db9624614faffc34a251c40d/src/__tests__/index.js#L36-L44

With virtual mocks as documented here: https://jestjs.io/docs/en/jest-object#jestmockmodulename-factory-options

jest.mock(
  '../moduleName',
  () => {
    /*
     * Custom implementation of a module that doesn't exist in JS,
     * like a generated module or a native module in react-native.
     */
  },
  {virtual: true},
);
kentcdodds commented 4 years ago

I tried this and it didn't work 🤷‍♂️