Skip to content

Mock not working with AdonisJS aliases #9

@hugoaboud

Description

@hugoaboud

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";

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions