My goal is to create a function that can switch based on the name of a class definition passed in as a parameter.
This function will simplify my testing process by allowing me to generate data for different classes using just one function.
generateMockDataForClass(className: Class, override){
if(className === Person){ return getPersonMockData(override)}
if(className === Dog){ return getDogMockData(override)}
...
}
This approach enables me to write tests like:
it('should process a person\'s information', ()=>{
const p = generateMockDataForClass(Person)
...
})
it('should compare 2 persons', ()=>{
const p = generateMockDataForClass(Person)
const p2 = generateMockDataForClass(Person, {name: 'Jane'})
})
However, I have not found a way to make this generic due to the lack of a class
type.