vendredi 11 octobre 2019

Assert that Set contains object when expected with a partial copy - Jest

I have a set that contains object of structure:

{
    param1: string,
    param2: string,
    param3: string
}

Would it be possible to perform the Set.has check against my set when attempting to match partial copies of the data contained? ie. an object containing:

{
    param2: string,
    param3: string
}

Where the expected object misses out the first param1 parameter...

I have attempted the following:

expect(mySet.has(expect.objectContaining(myData))).toBeTruthy();

I would have thought the expect.objectContaining() would have solved my issue...

I have also tried 'enriching' the expected data by adding:

myData.param1 = expect.any(String);

But this equally did not work...

Aucun commentaire:

Enregistrer un commentaire