I’m currently in the process of refactoring our unit tests. For one particular service, we used Jest to stub all of our search, filter, and aggregation. I came across this page which details how to stub searches.
The problem is, this doesn’t really seem any different from using the Jest.mockImplementation() for a search because you’re still returning a pre-canned answer for your entire query. I’d love to be able to do an Object.create() for stub objects and then verify that my query for those objects is behaving as I was expecting. For example:
const obj1 = Objects.create().myObj('obj1');
obj1.timestamp = Time.now();
const obj2 = Object.create().myObj('obj2');
obj2.timestamp = Timestamp.now().minusDays(1);
// this function would search ontology, order by timestamp in descending order, then take the top result.
expect(await myService.getMostRecentObj()).toEqual(obj1);
If anyone has any suggestions on how to stub this without stubbing the entire query that would be super helpful!