Skip to content

Instantly share code, notes, and snippets.

@brian-mann
brian-mann / app_spec.js
Created August 4, 2016 19:00
piechopper failing test
describe("PieChopper", function(){
beforeEach(function(){
// visit our local server running the application
//
// visiting before each test ensures the app
// gets reset to a clean state
//
// https://on.cypress.io/api/visit
cy.visit("http://localhost:8080")
})
$Cypress.register "Querying", (Cypress, _, $) ->
priorityElement = "input[type='submit'], button, a, label"
$expr = $.expr[":"]
$contains = $expr.contains
restoreContains = ->
$expr.contains = $contains
@brian-mann
brian-mann / loop.js
Created June 9, 2016 15:25
infinite command loop
it("infinitely loops", function(){
var loop = function(){
return cy.visit("something").get("whatever").do().something().else().then(function(){
return loop()
})
}
return loop()
})
Cypress.addDualCommand({
contains: function(subject, filter, text, options) {
var checkToAutomaticallyRetry, getErr, getFirstDeepestElement, getOpts, getPhrase, onConsole, resolveElements, selector, setEl;
if (options == null) {
options = {};
}
if (subject && !Cypress.Utils.hasElement(subject)) {
subject = null;
}
switch (false) {
@brian-mann
brian-mann / arrowdown.js
Created June 7, 2016 15:17
arrowdown custom command
Cypress.addChildCommand("arrowdown", function($el){
var evt = new Event("keydown", {
bubbles: true,
cancelable: true,
altKey: false,
ctrlKey: false,
metaKey: false,
shiftKey: false,
location: 0,
charCode: 0,
@brian-mann
brian-mann / spider.js
Last active May 25, 2016 18:58
spider with cypress
cy
.get("ul[class='nav menu'] a").then(function($a){
var hrefs = $a.map(function(i, el){
return Cypress.$(el).attr("href")
}).get()
hrefs.forEach(function(href){
cy.visit("http://your.url" + href).should("not.contain", "your 404 message")
// you might also try this
@brian-mann
brian-mann / iteration.js
Last active April 27, 2016 22:59
var vs no var
// if you open your chrome dev tools
// you'll see it log out the performance
// of each iterating in the console
var array = Array(100)
console.time("var")
for (i = 0; i < array.length; i++) {
var e = array[i]
for (j = 0; j < array.length; j++) {
@brian-mann
brian-mann / deprecation.coffee
Created March 26, 2016 16:48
fun deprecation warning
chalk = require("chalk")
asciify = require("asciify")
asteriks = Array(90).join("*")
log = {
newLine: (num = 1) ->
n = Array(num).join("\n")
console.log(n)
}
@brian-mann
brian-mann / gist:489ee81adaacff3992c4
Created August 11, 2015 18:27
example cypress.json
{
  "cypress": {
    "testFolder": "app/test/spec",
    "fixturesFolder": "app/test/spec/_fixtures",
    "supportFolder": "app/test/spec/_support",
    "viewportWidth": 1300,
    "viewportHeight": 660
  }
}

Example

/*
 * In window A's scripts, with A being on <http://example.com:8080>:
 */

var popup = window.open(...popup details...);

// When the popup has fully loaded, if not blocked by a popup blocker: