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

Mock not working with AdonisJS aliases #9

Open
hugoaboud opened this issue Jan 19, 2022 · 0 comments
Open

Mock not working with AdonisJS aliases #9

hugoaboud opened this issue Jan 19, 2022 · 0 comments

Comments

@hugoaboud
Copy link

I'm dealing with a pretty strange error, and I was finally able to isolate and reproduce it on a minimal repository: https://github.com/hugoaboud/adonis-jest-mock-issue.
The repository README contains a complete description of the problem and files involved.

I'm able to mock class methods from node_modules and use them through my application without any problem.
However, if I use AdonisJS aliases, such as App/, the mock has no effect.

In short:

import Controller from "../app/Controller"; // mock works
import Controller from "App/Controller";    // mock doesn't work

I assume this has to do with concurrency between Adonis IoC and Jest mock strategies. Do you have any thoughts?

There's an even simpler scenario, where the Service class doesn't belong to a dependency, but you import Controller with alias and Service without, or vice-versa:

// Mock doesn't work
import Controller from "App/Controller";
import Service from "../app/Service";
// Mock doesn't work
import Controller from "../app/Controller";
import Service from "App/Service";
// Mock works
import Controller from "App/Controller";
import Service from "App/Service";
// Mock works
import Controller from "../app/Controller";
import Service from "../app/Service";
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

1 participant