Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest test error - Cannot find module #50

Open
bytfolio opened this issue May 20, 2021 · 1 comment
Open

Jest test error - Cannot find module #50

bytfolio opened this issue May 20, 2021 · 1 comment

Comments

@bytfolio
Copy link

bytfolio commented May 20, 2021

I am using the RememberMe component in my Signin form (a React functional component in Meteor)

When I try running tests with Jest I get the following error:

Cannot find module 'meteor/tprzytula:remember-me' from 'imports/ui/components/signin/SigninForm.js'

Require stack:
  imports/ui/components/signin/SigninForm.js
  tests/Signin.test.js

  2 | import React, {useState, useRef} from 'react';
  3 | import {Accounts} from 'meteor/accounts-base';
> 4 | import RememberMe from 'meteor/tprzytula:remember-me';
    | ^

Here is my test code using Jest and Enzyme

  const wrapper = mount(<Signin t={() => {}} /> );

Is there a solution/workaround for this problem?

@tprzytula
Copy link
Owner

tprzytula commented May 27, 2021

Hi @bytfolio,

I haven't use Meteor in a while, but I would assume that Jest will be unable to use meteor packages and you would encounter the exact same issues with any meteor dependency that you import. I would suggest mocking them to avoid this problem, example: https://stackoverflow.com/questions/39548799/meteor-react-jest-testing

This article also mentions it: https://blog.meteor.com/real-world-unit-tests-with-meteor-and-jest-3d557e84e84a

It's interesting that you do not encounter this error for the accounts-base module, is this something that you are already mocking?

Mocking is of course not ideal as you would like to have your test give you as much confidence as you can that the logic works, but I'm not sure if there is any new way to make that work unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants