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

Module or class with Validator does not run with JUnit #287

Open
askaribragimov opened this issue Feb 22, 2022 · 3 comments
Open

Module or class with Validator does not run with JUnit #287

askaribragimov opened this issue Feb 22, 2022 · 3 comments

Comments

@askaribragimov
Copy link

I have a typescript file that starts like

// fastest-validator.ts file 

import Validator from "fastest-validator";
const v = new Validator();

// usual usage follows
export const responseSchemaValidator = v.compile(responseSchema);

This file is imported in my main file as

import {
    responseSchemaValidator 
} from "../fastest-validator";

and it works without an issue.

Observed: when I create a Jest Typescript test file with the same import I get an error

  ● Test suite failed to run

    TypeError: fastest_validator_1.default is not a constructor
        4 | var fastest_validator_1 = require("fastest-validator");
    > 5 | var v = new fastest_validator_1.default();

which makes it impossible for me to use the fastest_validator in the testing code.

Expected:

  • Jest tests can import fastest-validator code

I use:

    "babel-jest": "^27.0.1",
    "jest": "^27.5.1",
    "jest-junit": "^13.0.0",
    "ts-jest": "^27.1.3",
    "ts-node": "^10.0.0",
    "typescript": "^4.0.0"`
    "fastest-validator": "^1.12.0",
@erfanium
Copy link
Collaborator

https://www.typescriptlang.org/tsconfig#esModuleInterop

Do you have tried to set esModuleInterop: true in tsconfig?

@askaribragimov
Copy link
Author

@erfanium it's set to true

@erfanium
Copy link
Collaborator

#71

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