google / intermock

Mocking library to create mock objects with fake data for TypeScript interfaces
https://google.github.io/intermock/
Apache License 2.0
1.14k stars 71 forks source link

Support for enum arrays #16

Open yamazed opened 4 years ago

yamazed commented 4 years ago

I have:

enum StudentType { FullTime = 0, PartTime = 1, TeacherAssistant = 2 }

interface User { firstName: string; lastName: string; username: string; emailAddress: string; studentTypes: StudentType[] }

output becomes: { "Admin": { "firstName": "Libbie", "lastName": "Kuhic", "username": "Forest_Block", "emailAddress": "Richie.OHara@hotmail.com", "studentTypes": [ {}, {}, {} ], "adminRecord": { "studentsPassedEachYear": [ 64163 ] } }, }

expected: { "Admin": { "firstName": "Libbie", "lastName": "Kuhic", "username": "Forest_Block", "emailAddress": "Richie.OHara@hotmail.com", "studentTypes": [ 0,1,2 ], "adminRecord": { "studentsPassedEachYear": [ 64163 ] } }, }

ryanmcdermott commented 4 years ago

Thanks for your observation! Feel free to open a PR if you have a chance!

jasco commented 4 years ago

I believe I have a patch for this layered on top of #42. However, my tests always repeatedly populates a repeated, fixed value, 1. @ryanmcdermott is there an annotation or switch to randomize the value? Is this likely a bug in my implementation?

VFC-elindgren commented 3 years ago

Has this been resolved? I am finding that enums work, but with string enums

interface Phone {
    type: PhoneType;
    number: number;
}

enum PhoneType {
    WORK = "WORK",
    PERSONAL = "PERSONAL",
}

I'm getting a double quoted string:

phone: { type: '"PERSONAL"', number: 33488 }
Toolo commented 3 years ago

Also getting double quoted strings here 👍