Simple jest test just to check if the react component can render and it fails because I import
import { Meteor } from 'meteor/meteor'
the full error is...
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'm going to assume its because meteor doesn't build and therefore meteor/meteor
doesn't exist, any help in getting this to work will be appreciated. :)
I was right in my assumption, it's basically because meteor hasn't built the npm modules.
Despite what many may think, Jest is not just a test runner—it is a complete testing framework that has brought testing to another level. It's powerful but easy to use, so give it a try.
Cypress may be used to test anything that runs in a browser, making it simple to integrate with React, Angular, Vue, and other frameworks. Contrary to Jest and React-Testing-Library, Cypress does not include create-react-app by default. However, we can quickly install it using NPM or your preferred package manager.
As a result Cypress provides better, faster, and more reliable testing for anything that runs in a browser. Cypress works on any front-end framework or website. What is Jest? Painless JavaScript Unit Testing.
You can easily stub Meteor modules using the "moduleNameMapper" in your jest config 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 your test files.
Just do the same with all modules you need to mock (like Tracker
or ReactiveVar
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With