Currently, I am working on writing TypeScript tests in Mocha and have defined a test scenario as follows:
describe("IsDefined", () => {
it("should work correctly ...", () => {
class Test {
@IsDefined() p1: String = "";
@IsDefined() p2: Date = new Date();
@IsDefined() p3: Number = 0;
}
However, within the same describe
block, when I attempt to redefine the Test
class in another test like so:
it("should have accurately mapped ValidationContext values.", () => {
const options: ValidationOptions = {
each: true,
message: "Wazzzzaaaaaaapppppp????!!!!"
};
class Test {
@IsDefined(options) p1: String = "";
@IsDefined(options) p2: Date = new Date();
@IsDefined(options) p3: Number = 0;
}
const instance = new Test();
The unexpected issue arises. The original Test
class from the earlier test is still being utilized to create the instance
, leading to the passed options not being recognized by the decorator.
Renaming the class to Test2
resolves this problem, but I seek a more robust solution that does not rely solely on correct naming conventions for setup classes.
What is the appropriate method to set up preceding each it
function to prevent this occurrence?