fastest-validator
fastest-validator copied to clipboard
Module or class with Validator does not run with JUnit
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-validatorcode
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",
https://www.typescriptlang.org/tsconfig#esModuleInterop
Do you have tried to set esModuleInterop: true in tsconfig?
@erfanium it's set to true
https://github.com/icebob/fastest-validator/issues/71