Typescript-TDD / ts-auto-mock

Typescript transformer to unlock automatic mock creation for interfaces and classes
https://typescript-tdd.github.io/ts-auto-mock
MIT License
600 stars 16 forks source link

Error when creating mock of enum with negative value since Typescript 5.4 #1579

Closed hoi4 closed 4 months ago

hoi4 commented 4 months ago

Error when creating mock of enum with negative value since Typescript 5.4

When upgrading from Typescript 5.3.3 to 5.4.5, some of our tests are failing with the following error message:

Debug Failure. False expression: Negative numbers should be created in combination with createPrefixUnaryExpression

This is caused by calling createHydratedMock with an interface that includes a property of an enum type with a negative value, e.g.

enum TestEnum {
  VALUE_ONE = -1, // <-- This negative enum value seems to be the problem
  VALUE_TWO = 0,
  VALUE_THREE = 1
}

interface Test {
  readonly enumProp: TestEnum;
}

// in the test
const test = createHydratedMock<Test>(); // errors

Your environment

uittorio commented 4 months ago

Hey! Thank you for raising the issue! I will have look and let you know!

uittorio commented 4 months ago

Just released a new version to address the issue!! thank you again! Released in 3.7.3 https://github.com/Typescript-TDD/ts-auto-mock/blob/master/CHANGELOG.md

hoi4 commented 4 months ago

Works like a charm! I greatly appreciate the quick fix! Thank you! 🚀