How Do I Assert Against Objects With Spies In Cypress?
I am using Cypress spies to test client-side analytics. My intent in this test is to confirm that identify has been called like so: identify('myemail@email.com', { groupId: 1002,
Solution 1:
I've solved the problem in the OP title. Wrapping the analytics method in a spy was another problem, but I've updated the snippet in OP to reflect how I fixed that (i.e., changing sleep interval to 1ms).
You can assert on the object in a spy call's args using the callback signature of cy.should
:
const idProps = {
groupId: 1002,
groupName: "myGroup",
someProp: 1,
anotherProp: 2
};
cy.get("@identify").should(a => {
expect(a).to.be.calledWith("myemail@email.com");
// pardon the property index-ref style, using typescript and i'm lazyconst spy = a["getCalls"]();
const { args } = spy[0];
expect(args[1]).to.deep.equal(idProps);
});
Post a Comment for "How Do I Assert Against Objects With Spies In Cypress?"