Skip to content

Latest commit

 

History

History
 
 

stubbing-spying__google-analytics

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Stubbing Google Analytics

This is an example showing how to blacklist requests for www.google-analytics.com.

Even though we are preventing the actual GA script from loading, we can still stub the window.ga object and ensure its being called correctly.

  • Use blacklistHosts to block Google Analytics from receiving requests.
  • Use cy.stub() to verify that window.ga(...) was called with the correct arguments

Network Requests

This shows how the script is being blocked with a 503 server response code.

screen shot 2017-12-14 at 2 28 49 pm

The response headers also include the rule that caused the blockage.

screen shot 2017-12-14 at 2 28 26 pm