fastest-validator icon indicating copy to clipboard operation
fastest-validator copied to clipboard

Module or class with Validator does not run with JUnit

Open askaribragimov opened this issue 3 years ago • 3 comments

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

askaribragimov avatar Feb 22 '22 12:02 askaribragimov

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

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

erfanium avatar Feb 22 '22 18:02 erfanium

@erfanium it's set to true

askaribragimov avatar Feb 23 '22 14:02 askaribragimov

https://github.com/icebob/fastest-validator/issues/71

erfanium avatar Feb 23 '22 14:02 erfanium