Meteor reacts to jokes

A simple jest test to check if a component can respond and it fails because I import

import { Meteor } from 'meteor/meteor'

complete mistake ...

  PASS imports/__partials/Navigation/__tests__/Navigation.jest.js PASS imports/__layouts/AuthLayout/__tests__/AuthLayout.jest.js FAIL imports/features/oAuth/ui/LoginLayout/__tests__/LoginLayout.jest.js ● Test suite failed to run Cannot find module 'meteor/meteor' from 'index.js' at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:142:17) at Object.<anonymous> (imports/features/oAuth/ui/LoginLayout/index.js:2:41) at Object.<anonymous> (imports/features/oAuth/ui/LoginLayout/__tests__/LoginLayout.jest.js:4:40) PASS imports/staticTests/quickCheckboxTest/__tests__/CheckboxWithLabel.jest.js PASS imports/staticTests/quickLinkTest/__tests__/Link.react.jest.js 

I am going to assume because the meteorite is not being built and therefore meteor/meteor does not exist, any help in its work will be appreciated. :)

Edit ...

I was right in my assumption, this is mainly because the meteor did not build npm modules.

+8
javascript ecmascript-6 testing meteor jestjs
source share
1 answer

You can easily drown Meteor modules using "moduleNameMapper" in your jest configuration file:

 "moduleNameMapper": { "^meteor/(.*)": "<rootDir>/meteorMocks.js" } 

And in meteorMocks.js:

 export const Meteor = { call: () => null, // ... more stuff you'd like to mock on the Meteor object }; 

Then you can do

 import { Meteor } from 'meteor/meteor'; 

in test files.

Just do the same with all the modules you need to make fun of (e.g. Tracker or ReactiveVar ).

+10
source share

All Articles