I have a test where i'm expecting an array of objects. The below expect condition works fine. But each day due to the system under test behavior we need to change the expected data object array. So my question is, how to expect a pattern for these type of object array without expecting the exact value? or is there any other good way to handle this?
it('Verify the functionality of displaying correct data in Status grid table', function() {
expect(HomePage.getStatusGrid()).toEqual([
{ make : 'Make1', model : 'Model1', totLoads : '17.24', washDays : 'Wednesday', timeDay : '10:00-11:00' },
{ make : 'Make1', model : 'Model2', totLoads : '15.58', washDays : 'Wednesday', timeDay : '16:00-17:00' },
{ make : 'Make1', model : 'Model3', totLoads : '17.17', washDays : 'Monday', timeDay : '18:00-19:00' },
{ make : 'Make2', model : 'Model4', totLoads : '16.27', washDays : 'Monday', timeDay : '19:00-20:00' },
{ make : 'Make2', model : 'Model5', totLoads : '16.19', washDays : 'Thursday', timeDay : '19:00-20:00' },
{ make : 'Make2', model : 'Model6', totLoads : '15.01', washDays : 'Friday', timeDay : '10:00-11:00' },
{ make : 'Make3', model : 'Model7', totLoads : '16.94', washDays : 'Tuesday', timeDay : '11:00-12:00' },
{ make : 'Make3', model : 'Model8', totLoads : '15.72', washDays : 'Thursday', timeDay : '10:00-11:00' },
{ make : 'Make3', model : 'Model9', totLoads : '15.90', washDays : 'Saturday', timeDay : '16:00-17:00' }
]);
});
Having a custom matcher may help to hide the complexity of the matching checks and achieve reusability.
Though, a straight-forward approach to loop over rows in a grid and apply the
toMatch()matchers can be good enough:Note that if
HomePage.getStatusGrid()returns a promise, you would need to explicitly resolve it: