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

replaceEsm breaks usage of mongo db #488

Open
3 tasks done
paymog opened this issue Jun 5, 2022 · 2 comments
Open
3 tasks done

replaceEsm breaks usage of mongo db #488

paymog opened this issue Jun 5, 2022 · 2 comments

Comments

@paymog
Copy link

paymog commented Jun 5, 2022

Description

Using replaceEsm breaks usage of Mongo in the files under test

Issue

See repo for details. I have a module, A with a dependency on another module, B. Module A queries Mongo DB. When testing module A, I call replaceEsm('path/to/B') and this causes all queries to Mongo in module A to return nothing. However, I also have another module C which also queries Mongo. If I make calls to module C from the tests of module A, the mongo queries work as expected.

It seems there might be an issue with replaceEsm + imports in beforeEach + mongo db.

Environment

  • node -v output: v17.6.0
  • npm -v (or yarn --version) output: 8.5.1
  • npm ls testdouble (or yarn list testdouble) version:
    example@ /Users/paymahn/code/tripvector/example
    └── testdouble@3.16.5

Example Repo

Here's a minimal repo: https://github.com/paymog/testdouble-example

@giltayar
Copy link
Collaborator

Unfortunately, when running the sample repo it has a problem connecting to mongo, which makes sense given that I don't have mongo isntalled. If you can give me instructions on how to run this test with a mongo on docker, I'd love to help.

@giltayar
Copy link
Collaborator

Note that looking at the code, you're td.replaceEsm-ing the validations.js after you've imported the module, so even if mongo works, your mocking of that module won't really happen.

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