Currently, I am delving into the world of unit testing and have created a test to work on. Here is what I have so far:
const EXEPECTED: MergedFood = {
id: '1',
name: 'test mergedFood',
ingredients: {
'2': {
foodID: '2'
}
}
}
describe('addIngredientToMergedFood()', () => {
it('should add an ingredient to a mergedFood', () => {
const mergedFood: MergedFood = new MergedFood('1', 'test mergedFood');
const ingredient: Ingredient = new Ingredient('2')
const result: MergedFood = addIngredientToMergedFood(ingredient, mergedFood);
expect(result).toEqual(EXEPECTED);
})
})
Unfortunately, this test is failing and the error message I'm receiving is as follows:
Expected MergedFood({ id: '1', name: 'test mergedFood', ingredients: Object({ 2: Ingredient({ foodID: '2' }) }) }) to equal Object({ id: '1', name: 'test mergedFood', ingredients: Object({ 2: Object({ foodID: '2' }) }) })
Upon close inspection, the values and structure seem identical, but there seems to be some additional wrapping around the result
due to using constructors for creation.
My question then becomes, how do developers typically address this issue? Is it common practice to mock all data instead of using constructors (which might entail extra effort) OR is there a method to remove these wrappers?