cy.spy()

To wrap a method in a spy, use the cy.spy() command.

var obj = {
  foo () {}
}

var spy = cy.spy(obj, 'foo').as('anyArgs')

obj.foo()

expect(spy).to.be.called

cy.stub()

To create a stub and/or replace a function with a stub, use the cy.stub() command.

var obj = {
  foo () {}
}

var stub = cy.stub(obj, 'foo').as('foo')

obj.foo('foo', 'bar')

expect(stub).to.be.called

cy.clock()

To control time in the browser, use the cy.clock() command.

var now = new Date(Date.UTC(2017, 2, 14)).getTime()
cy.clock(now)
cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
cy.get('#clock-div').click()
  .should('have.text', '1489449600')
Click for current time!

cy.tick()

To move time in the browser, use the cy.tick() command.

var now = new Date(Date.UTC(2017, 2, 14)).getTime()

cy.clock(now)
cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
cy.get('#tick-div').click()
  .should('have.text', '1489449600')
cy.tick(10000) // 10 seconds passed
cy.get('#tick-div').click()
  .should('have.text', '1489449610')
Click for current time!