Issue:
I created a fixture that needs to do action based on information coming from the test. Here is an example of the needed info:
Created enum style class in ts:
export class Option {
public static readonly option1= new Option ('id','name', 'age');
public static readonly option2= new Option ('id,'name', 'age');
private constructor(public readonly id: string, public readonly name: string, public readonly age: string) {
}
}
My question is -how can I send this info (as object type) from test to my fixture?
Possible Solution:
solution 1:
I tried using the annotation option above test but it supports only string type:
{ type: 'option', description: Option .option1.id}
{ type: 'option', description: Option .option2.id}
Meaning when using it in my fixture I needed to convert it explicitly to work with object type
const OptionEnumArray = testInfo.annotations
.filter(annotation => annotation.type === 'option')
.map(annotation => {
switch (annotation.description) {
case Option.option1.id
return Option.option1
case Option.option2.id
return Option.option2
default:
return undefined; // Handle the default case
}
})
.filter(option => option !== undefined);
Solution 2:
I tried sending it using JSON parsing option and it worked after in my fixture to json it back but it is not user friendly and not clear code in my opinion.
JSON.stringify(Option .option1)
Do you have any other idea for solution besides for using annotations?