mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-31 03:29:43 -06:00
decaffeinate: Convert error_messages.coffee and 10 other files to JS
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,209 +1,236 @@
|
||||
$ = Cypress.$.bind(Cypress)
|
||||
_ = Cypress._
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const $ = Cypress.$.bind(Cypress);
|
||||
const {
|
||||
_
|
||||
} = Cypress;
|
||||
|
||||
$dom = require("../../../../src/dom")
|
||||
const $dom = require("../../../../src/dom");
|
||||
|
||||
describe "src/cy/commands/misc", ->
|
||||
before ->
|
||||
cy
|
||||
.visit("/fixtures/jquery.html")
|
||||
.then (win) ->
|
||||
@body = win.document.body.outerHTML
|
||||
describe("src/cy/commands/misc", function() {
|
||||
before(() => cy
|
||||
.visit("/fixtures/jquery.html")
|
||||
.then(function(win) {
|
||||
return this.body = win.document.body.outerHTML;
|
||||
}));
|
||||
|
||||
beforeEach ->
|
||||
doc = cy.state("document")
|
||||
beforeEach(function() {
|
||||
const doc = cy.state("document");
|
||||
|
||||
$(doc.body).empty().html(@body)
|
||||
return $(doc.body).empty().html(this.body);
|
||||
});
|
||||
|
||||
context "#end", ->
|
||||
it "nulls out the subject", ->
|
||||
cy.noop({}).end().then (subject) ->
|
||||
expect(subject).to.be.null
|
||||
context("#end", () => it("nulls out the subject", () => cy.noop({}).end().then(subject => expect(subject).to.be.null)));
|
||||
|
||||
context "#log", ->
|
||||
it "nulls out the subject", ->
|
||||
cy.wrap({}).log("foo").then (subject) ->
|
||||
expect(subject).to.be.null
|
||||
context("#log", function() {
|
||||
it("nulls out the subject", () => cy.wrap({}).log("foo").then(subject => expect(subject).to.be.null));
|
||||
|
||||
describe ".log", ->
|
||||
beforeEach ->
|
||||
@logs = []
|
||||
return describe(".log", function() {
|
||||
beforeEach(function() {
|
||||
this.logs = [];
|
||||
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
@lastLog = log
|
||||
@logs.push(log)
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
this.lastLog = log;
|
||||
return this.logs.push(log);
|
||||
});
|
||||
|
||||
return null
|
||||
return null;
|
||||
});
|
||||
|
||||
it "logs immediately", (done) ->
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
cy.removeAllListeners("log:added")
|
||||
it("logs immediately", function(done) {
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
cy.removeAllListeners("log:added");
|
||||
|
||||
expect(log.get("message")).to.eq "foo, {foo: bar}"
|
||||
expect(log.get("name")).to.eq "log"
|
||||
expect(log.get("end")).to.be.true
|
||||
done()
|
||||
expect(log.get("message")).to.eq("foo, {foo: bar}");
|
||||
expect(log.get("name")).to.eq("log");
|
||||
expect(log.get("end")).to.be.true;
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.log("foo", {foo: "bar"}).then =>
|
||||
lastLog = @lastLog
|
||||
return cy.log("foo", {foo: "bar"}).then(() => {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
expect(lastLog.get("ended")).to.be.true
|
||||
expect(lastLog.get("snapshots").length).to.eq(1)
|
||||
expect(lastLog.get("snapshots")[0]).to.be.an("object")
|
||||
expect(lastLog.get("ended")).to.be.true;
|
||||
expect(lastLog.get("snapshots").length).to.eq(1);
|
||||
return expect(lastLog.get("snapshots")[0]).to.be.an("object");
|
||||
});
|
||||
});
|
||||
|
||||
it "consoleProps", ->
|
||||
cy.log("foobarbaz", [{}]).then ->
|
||||
expect(@lastLog.invoke("consoleProps")).to.deep.eq({
|
||||
Command: "log"
|
||||
args: [{}]
|
||||
message: "foobarbaz"
|
||||
})
|
||||
return it("consoleProps", () => cy.log("foobarbaz", [{}]).then(function() {
|
||||
return expect(this.lastLog.invoke("consoleProps")).to.deep.eq({
|
||||
Command: "log",
|
||||
args: [{}],
|
||||
message: "foobarbaz"
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
context "#wrap", ->
|
||||
beforeEach ->
|
||||
@remoteWindow = cy.state("window")
|
||||
return context("#wrap", function() {
|
||||
beforeEach(function() {
|
||||
this.remoteWindow = cy.state("window");
|
||||
|
||||
delete @remoteWindow.$.fn.foo
|
||||
return delete this.remoteWindow.$.fn.foo;
|
||||
});
|
||||
|
||||
it "sets the subject to the first argument", ->
|
||||
cy.wrap({}).then (subject) ->
|
||||
expect(subject).to.deep.eq {}
|
||||
it("sets the subject to the first argument", () => cy.wrap({}).then(subject => expect(subject).to.deep.eq({})));
|
||||
|
||||
## https://github.com/cypress-io/cypress/issues/3241
|
||||
it "cy.wrap(undefined) should retry", () ->
|
||||
stub = cy.stub()
|
||||
//# https://github.com/cypress-io/cypress/issues/3241
|
||||
it("cy.wrap(undefined) should retry", function() {
|
||||
const stub = cy.stub();
|
||||
|
||||
cy.wrap().should ->
|
||||
stub()
|
||||
expect(stub).to.be.calledTwice
|
||||
cy.wrap().should(function() {
|
||||
stub();
|
||||
return expect(stub).to.be.calledTwice;
|
||||
});
|
||||
|
||||
cy.wrap(undefined).should ->
|
||||
stub()
|
||||
expect(stub.callCount).to.eq(4)
|
||||
return cy.wrap(undefined).should(function() {
|
||||
stub();
|
||||
return expect(stub.callCount).to.eq(4);
|
||||
});
|
||||
});
|
||||
|
||||
it "can wrap jquery objects and continue to chain", ->
|
||||
@remoteWindow.$.fn.foo = "foo"
|
||||
it("can wrap jquery objects and continue to chain", function() {
|
||||
this.remoteWindow.$.fn.foo = "foo";
|
||||
|
||||
append = =>
|
||||
setTimeout =>
|
||||
$("<li class='appended'>appended</li>").appendTo cy.$$("#list")
|
||||
, 50
|
||||
const append = () => {
|
||||
return setTimeout(() => {
|
||||
return $("<li class='appended'>appended</li>").appendTo(cy.$$("#list"));
|
||||
}
|
||||
, 50);
|
||||
};
|
||||
|
||||
cy.on "command:retry", _.after(2, _.once(append))
|
||||
cy.on("command:retry", _.after(2, _.once(append)));
|
||||
|
||||
cy.get("#list").then ($ul) ->
|
||||
return cy.get("#list").then($ul => cy
|
||||
// ensure that assertions are based on the real subject
|
||||
// and not the cy subject - therefore foo should be defined
|
||||
.wrap($ul).should("have.property", "foo")
|
||||
|
||||
cy
|
||||
# ensure that assertions are based on the real subject
|
||||
# and not the cy subject - therefore foo should be defined
|
||||
.wrap($ul).should("have.property", "foo")
|
||||
// then re-wrap $ul and ensure that the subject passed
|
||||
// downstream is the cypress instance
|
||||
.wrap($ul)
|
||||
.find("li.appended")
|
||||
.then($li => //# must use explicit non cy.should
|
||||
//# else this test will always pass
|
||||
expect($li.length).to.eq(1)));
|
||||
});
|
||||
|
||||
# then re-wrap $ul and ensure that the subject passed
|
||||
# downstream is the cypress instance
|
||||
.wrap($ul)
|
||||
.find("li.appended")
|
||||
.then ($li) ->
|
||||
## must use explicit non cy.should
|
||||
## else this test will always pass
|
||||
expect($li.length).to.eq(1)
|
||||
//# TODO: fix this test in 4.0 when we refactor validating subjects
|
||||
it.skip("throws a good error when wrapping mixed types: element + string", () => cy.get("button").then(function($btn) {
|
||||
const btn = $btn.get(0);
|
||||
|
||||
## TODO: fix this test in 4.0 when we refactor validating subjects
|
||||
it.skip "throws a good error when wrapping mixed types: element + string", ->
|
||||
cy.get("button").then ($btn) ->
|
||||
btn = $btn.get(0)
|
||||
return cy.wrap([btn, "asdf"]).click();
|
||||
}));
|
||||
|
||||
cy.wrap([btn, "asdf"]).click()
|
||||
it("can wrap an array of DOM elements and pass command validation", () => cy.get("button").then(function($btn) {
|
||||
const btn = $btn.get(0);
|
||||
|
||||
it "can wrap an array of DOM elements and pass command validation", ->
|
||||
cy.get("button").then ($btn) ->
|
||||
btn = $btn.get(0)
|
||||
cy.wrap([btn]).click().then($btn => expect($dom.isJquery($btn)).to.be.true);
|
||||
|
||||
cy.wrap([btn]).click().then ($btn) ->
|
||||
expect($dom.isJquery($btn)).to.be.true
|
||||
return cy.wrap([btn, btn]).click({ multiple: true }).then($btns => expect($dom.isJquery($btns)).to.be.true);
|
||||
}));
|
||||
|
||||
cy.wrap([btn, btn]).click({ multiple: true }).then ($btns) ->
|
||||
expect($dom.isJquery($btns)).to.be.true
|
||||
it("can wrap an array of window without it being altered", () => cy.window().then(win => cy.wrap([win]).then(function(arr) {
|
||||
expect(arr).to.be.an('array');
|
||||
return expect(Array.isArray(arr)).to.be.true;
|
||||
})));
|
||||
|
||||
it "can wrap an array of window without it being altered", ->
|
||||
cy.window().then (win) ->
|
||||
cy.wrap([win]).then (arr) ->
|
||||
expect(arr).to.be.an('array')
|
||||
expect(Array.isArray(arr)).to.be.true
|
||||
it("can wrap an array of document without it being altered", () => cy.document().then(doc => cy.wrap([doc]).then(function(arr) {
|
||||
expect(arr).to.be.an('array');
|
||||
expect(Array.isArray(arr)).to.be.true;
|
||||
return expect(arr[0]).to.eq(doc);
|
||||
})));
|
||||
|
||||
it "can wrap an array of document without it being altered", ->
|
||||
cy.document().then (doc) ->
|
||||
cy.wrap([doc]).then (arr) ->
|
||||
expect(arr).to.be.an('array')
|
||||
expect(Array.isArray(arr)).to.be.true
|
||||
expect(arr[0]).to.eq(doc)
|
||||
//# https://github.com/cypress-io/cypress/issues/2927
|
||||
it("can properly handle objects with 'jquery' functions as properties", () => //# the root issue here has to do with the fact that window.jquery points
|
||||
//# to the jquery constructor, but not an actual jquery instance and
|
||||
//# we need to account for that...
|
||||
cy.window().then(function(win) {
|
||||
win.jquery = function() {};
|
||||
|
||||
## https://github.com/cypress-io/cypress/issues/2927
|
||||
it "can properly handle objects with 'jquery' functions as properties", ->
|
||||
## the root issue here has to do with the fact that window.jquery points
|
||||
## to the jquery constructor, but not an actual jquery instance and
|
||||
## we need to account for that...
|
||||
cy.window().then (win) ->
|
||||
win.jquery = ->
|
||||
return win;
|
||||
}));
|
||||
|
||||
return win
|
||||
describe("errors", function() {
|
||||
it("throws when wrapping an array of windows", function(done) {
|
||||
cy.on("fail", err => {
|
||||
expect(err.message).to.include("`cy.scrollTo()` failed because it requires a DOM element.");
|
||||
expect(err.message).to.include("[<window>]");
|
||||
expect(err.message).to.include("All 2 subject validations failed on this subject.");
|
||||
return done();
|
||||
});
|
||||
|
||||
describe "errors", ->
|
||||
it "throws when wrapping an array of windows", (done) ->
|
||||
cy.on "fail", (err) =>
|
||||
expect(err.message).to.include "`cy.scrollTo()` failed because it requires a DOM element."
|
||||
expect(err.message).to.include "[<window>]"
|
||||
expect(err.message).to.include "All 2 subject validations failed on this subject."
|
||||
done()
|
||||
return cy.window().then(win => cy.wrap([win]).scrollTo("bottom"));
|
||||
});
|
||||
|
||||
cy.window().then (win) ->
|
||||
cy.wrap([win]).scrollTo("bottom")
|
||||
return it("throws when wrapping an array of documents", function(done) {
|
||||
cy.on("fail", err => {
|
||||
expect(err.message).to.include("`cy.screenshot()` failed because it requires a DOM element.");
|
||||
expect(err.message).to.include("[<document>]");
|
||||
expect(err.message).to.include("All 3 subject validations failed on this subject.");
|
||||
return done();
|
||||
});
|
||||
|
||||
it "throws when wrapping an array of documents", (done) ->
|
||||
cy.on "fail", (err) =>
|
||||
expect(err.message).to.include "`cy.screenshot()` failed because it requires a DOM element."
|
||||
expect(err.message).to.include "[<document>]"
|
||||
expect(err.message).to.include "All 3 subject validations failed on this subject."
|
||||
done()
|
||||
return cy.document().then(doc => cy.wrap([doc]).screenshot());
|
||||
});
|
||||
});
|
||||
|
||||
cy.document().then (doc) ->
|
||||
cy.wrap([doc]).screenshot()
|
||||
return describe(".log", function() {
|
||||
beforeEach(function() {
|
||||
this.logs = [];
|
||||
|
||||
describe ".log", ->
|
||||
beforeEach ->
|
||||
@logs = []
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
this.lastLog = log;
|
||||
return this.logs.push(log);
|
||||
});
|
||||
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
@lastLog = log
|
||||
@logs.push(log)
|
||||
return null;
|
||||
});
|
||||
|
||||
return null
|
||||
it("logs immediately", function(done) {
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
cy.removeAllListeners("log:added");
|
||||
|
||||
it "logs immediately", (done) ->
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
cy.removeAllListeners("log:added")
|
||||
expect(log.get("message")).to.eq("{}");
|
||||
expect(log.get("name")).to.eq("wrap");
|
||||
expect(log.get("end")).not.to.be.ok;
|
||||
return done();
|
||||
});
|
||||
|
||||
expect(log.get("message")).to.eq "{}"
|
||||
expect(log.get("name")).to.eq "wrap"
|
||||
expect(log.get("end")).not.to.be.ok
|
||||
done()
|
||||
return cy.wrap({}).then(() => {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
cy.wrap({}).then =>
|
||||
lastLog = @lastLog
|
||||
expect(lastLog.get("ended")).to.be.true;
|
||||
expect(lastLog.get("snapshots").length).to.eq(1);
|
||||
return expect(lastLog.get("snapshots")[0]).to.be.an("object");
|
||||
});
|
||||
});
|
||||
|
||||
expect(lastLog.get("ended")).to.be.true
|
||||
expect(lastLog.get("snapshots").length).to.eq(1)
|
||||
expect(lastLog.get("snapshots")[0]).to.be.an("object")
|
||||
return it("stringifies DOM elements and sets $el", function() {
|
||||
const body = $("body");
|
||||
|
||||
it "stringifies DOM elements and sets $el", ->
|
||||
body = $("body")
|
||||
return cy.wrap(body).then(function($el) {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
cy.wrap(body).then ($el) ->
|
||||
lastLog = @lastLog
|
||||
//# internally we store the real remote jquery
|
||||
//# instance instead of the cypress one
|
||||
expect(lastLog.get("$el")).not.to.eq($el);
|
||||
|
||||
## internally we store the real remote jquery
|
||||
## instance instead of the cypress one
|
||||
expect(lastLog.get("$el")).not.to.eq($el)
|
||||
|
||||
## but make sure they are the same DOM object
|
||||
expect(lastLog.get("$el").get(0)).to.eq $el.get(0)
|
||||
expect(lastLog.get("message")).to.eq "<body>"
|
||||
//# but make sure they are the same DOM object
|
||||
expect(lastLog.get("$el").get(0)).to.eq($el.get(0));
|
||||
return expect(lastLog.get("message")).to.eq("<body>");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,74 +1,88 @@
|
||||
describe "src/cy/commands/popups", ->
|
||||
context "alert", ->
|
||||
beforeEach ->
|
||||
cy.visit("/fixtures/generic.html")
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("src/cy/commands/popups", function() {
|
||||
context("alert", function() {
|
||||
beforeEach(function() {
|
||||
cy.visit("/fixtures/generic.html");
|
||||
|
||||
@logs = []
|
||||
this.logs = [];
|
||||
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
if attrs.name is "alert"
|
||||
@logs.push(log)
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
if (attrs.name === "alert") {
|
||||
return this.logs.push(log);
|
||||
}
|
||||
});
|
||||
|
||||
return null
|
||||
return null;
|
||||
});
|
||||
|
||||
it "logs the alert", ->
|
||||
cy.window().then (win) ->
|
||||
win.alert("fooooo")
|
||||
.then ->
|
||||
expect(@logs.length).to.eq(1)
|
||||
expect(@logs[0].get("name")).to.eq("alert")
|
||||
expect(@logs[0].get("message")).to.eq("fooooo")
|
||||
return it("logs the alert", () => cy.window().then(win => win.alert("fooooo")).then(function() {
|
||||
expect(this.logs.length).to.eq(1);
|
||||
expect(this.logs[0].get("name")).to.eq("alert");
|
||||
expect(this.logs[0].get("message")).to.eq("fooooo");
|
||||
|
||||
consoleProps = @logs[0].invoke("consoleProps")
|
||||
const consoleProps = this.logs[0].invoke("consoleProps");
|
||||
|
||||
expect(consoleProps).to.deep.eq({
|
||||
Event: "alert"
|
||||
Alerted: "fooooo"
|
||||
})
|
||||
return expect(consoleProps).to.deep.eq({
|
||||
Event: "alert",
|
||||
Alerted: "fooooo"
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
context "confirm", ->
|
||||
beforeEach ->
|
||||
cy.visit("/fixtures/generic.html")
|
||||
return context("confirm", function() {
|
||||
beforeEach(function() {
|
||||
cy.visit("/fixtures/generic.html");
|
||||
|
||||
@logs = []
|
||||
this.logs = [];
|
||||
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
if attrs.name is "confirm"
|
||||
@logs.push(log)
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
if (attrs.name === "confirm") {
|
||||
return this.logs.push(log);
|
||||
}
|
||||
});
|
||||
|
||||
return null
|
||||
return null;
|
||||
});
|
||||
|
||||
it "logs the confirm", ->
|
||||
cy.window().then (win) ->
|
||||
win.confirm("Delete hard drive?")
|
||||
.then ->
|
||||
expect(@logs.length).to.eq(1)
|
||||
expect(@logs[0].get("name")).to.eq("confirm")
|
||||
expect(@logs[0].get("message")).to.eq("Delete hard drive?")
|
||||
it("logs the confirm", () => cy.window().then(win => win.confirm("Delete hard drive?")).then(function() {
|
||||
expect(this.logs.length).to.eq(1);
|
||||
expect(this.logs[0].get("name")).to.eq("confirm");
|
||||
expect(this.logs[0].get("message")).to.eq("Delete hard drive?");
|
||||
|
||||
consoleProps = @logs[0].invoke("consoleProps")
|
||||
const consoleProps = this.logs[0].invoke("consoleProps");
|
||||
|
||||
expect(consoleProps).to.deep.eq({
|
||||
Event: "confirm"
|
||||
Prompted: "Delete hard drive?"
|
||||
Confirmed: true
|
||||
})
|
||||
return expect(consoleProps).to.deep.eq({
|
||||
Event: "confirm",
|
||||
Prompted: "Delete hard drive?",
|
||||
Confirmed: true
|
||||
});
|
||||
}));
|
||||
|
||||
it "can turn on and off confirmation", ->
|
||||
cy.on "window:confirm", (str) ->
|
||||
switch str
|
||||
when "foo" then false
|
||||
when "bar" then true
|
||||
when "baz" then undefined
|
||||
return it("can turn on and off confirmation", function() {
|
||||
cy.on("window:confirm", function(str) {
|
||||
switch (str) {
|
||||
case "foo": return false;
|
||||
case "bar": return true;
|
||||
case "baz": return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
cy.window().then (win) ->
|
||||
confirmedFoo = win.confirm("foo")
|
||||
expect(confirmedFoo).to.be.false
|
||||
return cy.window().then(function(win) {
|
||||
const confirmedFoo = win.confirm("foo");
|
||||
expect(confirmedFoo).to.be.false;
|
||||
|
||||
confirmedBar = win.confirm("bar")
|
||||
expect(confirmedBar).to.be.true
|
||||
const confirmedBar = win.confirm("bar");
|
||||
expect(confirmedBar).to.be.true;
|
||||
|
||||
## undefined is not strictly false
|
||||
## so the confirmation should be true
|
||||
confirmedBaz = win.confirm("baz")
|
||||
expect(confirmedBaz).to.be.true
|
||||
//# undefined is not strictly false
|
||||
//# so the confirmation should be true
|
||||
const confirmedBaz = win.confirm("baz");
|
||||
return expect(confirmedBaz).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,219 +1,271 @@
|
||||
_ = Cypress._
|
||||
Promise = Cypress.Promise
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const {
|
||||
_
|
||||
} = Cypress;
|
||||
const {
|
||||
Promise
|
||||
} = Cypress;
|
||||
|
||||
describe "src/cy/commands/task", ->
|
||||
context "#task", ->
|
||||
beforeEach ->
|
||||
Cypress.config("taskTimeout", 2500)
|
||||
describe("src/cy/commands/task", () => context("#task", function() {
|
||||
beforeEach(function() {
|
||||
Cypress.config("taskTimeout", 2500);
|
||||
|
||||
cy.stub(Cypress, "backend").callThrough()
|
||||
return cy.stub(Cypress, "backend").callThrough();
|
||||
});
|
||||
|
||||
it "calls Cypress.backend('task') with the right options", ->
|
||||
Cypress.backend.resolves(null)
|
||||
it("calls Cypress.backend('task') with the right options", function() {
|
||||
Cypress.backend.resolves(null);
|
||||
|
||||
cy.task("foo").then ->
|
||||
expect(Cypress.backend).to.be.calledWith("task", {
|
||||
task: "foo"
|
||||
timeout: 2500
|
||||
arg: undefined
|
||||
})
|
||||
return cy.task("foo").then(() => expect(Cypress.backend).to.be.calledWith("task", {
|
||||
task: "foo",
|
||||
timeout: 2500,
|
||||
arg: undefined
|
||||
}));
|
||||
});
|
||||
|
||||
it "passes through arg", ->
|
||||
Cypress.backend.resolves(null)
|
||||
it("passes through arg", function() {
|
||||
Cypress.backend.resolves(null);
|
||||
|
||||
cy.task("foo", { foo: "foo" }).then ->
|
||||
expect(Cypress.backend).to.be.calledWith("task", {
|
||||
task: "foo"
|
||||
timeout: 2500
|
||||
arg: {
|
||||
foo: "foo"
|
||||
}
|
||||
})
|
||||
return cy.task("foo", { foo: "foo" }).then(() => expect(Cypress.backend).to.be.calledWith("task", {
|
||||
task: "foo",
|
||||
timeout: 2500,
|
||||
arg: {
|
||||
foo: "foo"
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
it "really works", ->
|
||||
cy.task("return:arg", "works").should("eq", "works")
|
||||
it("really works", () => cy.task("return:arg", "works").should("eq", "works"));
|
||||
|
||||
describe ".log", ->
|
||||
beforeEach ->
|
||||
@logs = []
|
||||
describe(".log", function() {
|
||||
beforeEach(function() {
|
||||
this.logs = [];
|
||||
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
@lastLog = log
|
||||
@logs.push(log)
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
this.lastLog = log;
|
||||
return this.logs.push(log);
|
||||
});
|
||||
|
||||
Cypress.backend.resolves(null)
|
||||
Cypress.backend.resolves(null);
|
||||
|
||||
return null
|
||||
return null;
|
||||
});
|
||||
|
||||
it "can turn off logging", ->
|
||||
cy.task("foo", null, { log: false }).then ->
|
||||
logs = _.filter @logs, (log) ->
|
||||
log.get("name") is "task"
|
||||
it("can turn off logging", () => cy.task("foo", null, { log: false }).then(function() {
|
||||
const logs = _.filter(this.logs, log => log.get("name") === "task");
|
||||
|
||||
expect(logs.length).to.eq(0)
|
||||
return expect(logs.length).to.eq(0);
|
||||
}));
|
||||
|
||||
it "logs immediately before resolving", ->
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
if attrs.name is "task"
|
||||
expect(log.get("state")).to.eq("pending")
|
||||
expect(log.get("message")).to.eq("foo")
|
||||
return it("logs immediately before resolving", function() {
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
if (attrs.name === "task") {
|
||||
expect(log.get("state")).to.eq("pending");
|
||||
return expect(log.get("message")).to.eq("foo");
|
||||
}
|
||||
});
|
||||
|
||||
cy.task("foo").then =>
|
||||
throw new Error("failed to log before resolving") unless @lastLog
|
||||
return cy.task("foo").then(() => {
|
||||
if (!this.lastLog) { throw new Error("failed to log before resolving"); }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe "timeout", ->
|
||||
beforeEach ->
|
||||
Cypress.backend.resolves(null)
|
||||
describe("timeout", function() {
|
||||
beforeEach(() => Cypress.backend.resolves(null));
|
||||
|
||||
it "defaults timeout to Cypress.config(taskTimeout)", ->
|
||||
timeout = cy.spy(Promise.prototype, "timeout")
|
||||
it("defaults timeout to Cypress.config(taskTimeout)", function() {
|
||||
const timeout = cy.spy(Promise.prototype, "timeout");
|
||||
|
||||
cy.task("foo").then ->
|
||||
expect(timeout).to.be.calledWith(2500)
|
||||
return cy.task("foo").then(() => expect(timeout).to.be.calledWith(2500));
|
||||
});
|
||||
|
||||
it "can override timeout", ->
|
||||
timeout = cy.spy(Promise.prototype, "timeout")
|
||||
it("can override timeout", function() {
|
||||
const timeout = cy.spy(Promise.prototype, "timeout");
|
||||
|
||||
cy.task("foo", null, { timeout: 1000 }).then ->
|
||||
expect(timeout).to.be.calledWith(1000)
|
||||
return cy.task("foo", null, { timeout: 1000 }).then(() => expect(timeout).to.be.calledWith(1000));
|
||||
});
|
||||
|
||||
it "clears the current timeout and restores after success", ->
|
||||
cy.timeout(100)
|
||||
return it("clears the current timeout and restores after success", function() {
|
||||
cy.timeout(100);
|
||||
|
||||
clearTimeout = cy.spy(cy, "clearTimeout")
|
||||
const clearTimeout = cy.spy(cy, "clearTimeout");
|
||||
|
||||
cy.on "task", =>
|
||||
expect(clearTimeout).to.be.calledOnce
|
||||
cy.on("task", () => {
|
||||
return expect(clearTimeout).to.be.calledOnce;
|
||||
});
|
||||
|
||||
cy.task("foo").then ->
|
||||
expect(cy.timeout()).to.eq(100)
|
||||
return cy.task("foo").then(() => expect(cy.timeout()).to.eq(100));
|
||||
});
|
||||
});
|
||||
|
||||
describe "errors", ->
|
||||
beforeEach ->
|
||||
Cypress.config("defaultCommandTimeout", 50)
|
||||
return describe("errors", function() {
|
||||
beforeEach(function() {
|
||||
Cypress.config("defaultCommandTimeout", 50);
|
||||
|
||||
@logs = []
|
||||
this.logs = [];
|
||||
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
if attrs.name is "task"
|
||||
@lastLog = log
|
||||
@logs.push(log)
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
if (attrs.name === "task") {
|
||||
this.lastLog = log;
|
||||
return this.logs.push(log);
|
||||
}
|
||||
});
|
||||
|
||||
return null
|
||||
return null;
|
||||
});
|
||||
|
||||
it "throws when task is absent", (done) ->
|
||||
cy.on "fail", (err) =>
|
||||
lastLog = @lastLog
|
||||
it("throws when task is absent", function(done) {
|
||||
cy.on("fail", err => {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
expect(@logs.length).to.eq(1)
|
||||
expect(lastLog.get("error")).to.eq(err)
|
||||
expect(lastLog.get("state")).to.eq("failed")
|
||||
expect(err.message).to.eq("`cy.task()` must be passed a non-empty string as its 1st argument. You passed: ``.")
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task")
|
||||
done()
|
||||
expect(this.logs.length).to.eq(1);
|
||||
expect(lastLog.get("error")).to.eq(err);
|
||||
expect(lastLog.get("state")).to.eq("failed");
|
||||
expect(err.message).to.eq("`cy.task()` must be passed a non-empty string as its 1st argument. You passed: ``.");
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task");
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.task()
|
||||
return cy.task();
|
||||
});
|
||||
|
||||
it "throws when task isn't a string", (done) ->
|
||||
cy.on "fail", (err) =>
|
||||
lastLog = @lastLog
|
||||
it("throws when task isn't a string", function(done) {
|
||||
cy.on("fail", err => {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
expect(@logs.length).to.eq(1)
|
||||
expect(lastLog.get("error")).to.eq(err)
|
||||
expect(lastLog.get("state")).to.eq("failed")
|
||||
expect(err.message).to.eq("`cy.task()` must be passed a non-empty string as its 1st argument. You passed: `3`.")
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task")
|
||||
done()
|
||||
expect(this.logs.length).to.eq(1);
|
||||
expect(lastLog.get("error")).to.eq(err);
|
||||
expect(lastLog.get("state")).to.eq("failed");
|
||||
expect(err.message).to.eq("`cy.task()` must be passed a non-empty string as its 1st argument. You passed: `3`.");
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task");
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.task(3)
|
||||
return cy.task(3);
|
||||
});
|
||||
|
||||
it "throws when task is an empty string", (done) ->
|
||||
cy.on "fail", (err) =>
|
||||
lastLog = @lastLog
|
||||
it("throws when task is an empty string", function(done) {
|
||||
cy.on("fail", err => {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
expect(@logs.length).to.eq(1)
|
||||
expect(lastLog.get("error")).to.eq(err)
|
||||
expect(lastLog.get("state")).to.eq("failed")
|
||||
expect(err.message).to.eq("`cy.task()` must be passed a non-empty string as its 1st argument. You passed: ``.")
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task")
|
||||
done()
|
||||
expect(this.logs.length).to.eq(1);
|
||||
expect(lastLog.get("error")).to.eq(err);
|
||||
expect(lastLog.get("state")).to.eq("failed");
|
||||
expect(err.message).to.eq("`cy.task()` must be passed a non-empty string as its 1st argument. You passed: ``.");
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task");
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.task('')
|
||||
return cy.task('');
|
||||
});
|
||||
|
||||
it "throws when the task errors", (done) ->
|
||||
Cypress.backend.rejects(new Error("task failed"))
|
||||
it("throws when the task errors", function(done) {
|
||||
Cypress.backend.rejects(new Error("task failed"));
|
||||
|
||||
cy.on "fail", (err) =>
|
||||
lastLog = @lastLog
|
||||
cy.on("fail", err => {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
expect(@logs.length).to.eq(1)
|
||||
expect(lastLog.get("error")).to.eq(err)
|
||||
expect(lastLog.get("state")).to.eq("failed")
|
||||
expect(this.logs.length).to.eq(1);
|
||||
expect(lastLog.get("error")).to.eq(err);
|
||||
expect(lastLog.get("state")).to.eq("failed");
|
||||
|
||||
expect(err.message).to.include("`cy.task('foo')` failed with the following error:")
|
||||
expect(err.message).to.include("> task failed")
|
||||
done()
|
||||
expect(err.message).to.include("`cy.task('foo')` failed with the following error:");
|
||||
expect(err.message).to.include("> task failed");
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.task("foo")
|
||||
return cy.task("foo");
|
||||
});
|
||||
|
||||
it "throws when task is not registered by plugin", (done) ->
|
||||
cy.on "fail", (err) =>
|
||||
lastLog = @lastLog
|
||||
it("throws when task is not registered by plugin", function(done) {
|
||||
cy.on("fail", err => {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
expect(@logs.length).to.eq(1)
|
||||
expect(lastLog.get("error")).to.eq(err)
|
||||
expect(lastLog.get("state")).to.eq("failed")
|
||||
expect(this.logs.length).to.eq(1);
|
||||
expect(lastLog.get("error")).to.eq(err);
|
||||
expect(lastLog.get("state")).to.eq("failed");
|
||||
|
||||
expect(err.message).to.eq("`cy.task('bar')` failed with the following error:\n\nThe task 'bar' was not handled in the plugins file. The following tasks are registered: return:arg, wait, create:long:file\n\nFix this in your plugins file here:\n#{Cypress.config('pluginsFile')}\n\nhttps://on.cypress.io/api/task")
|
||||
done()
|
||||
expect(err.message).to.eq(`\`cy.task('bar')\` failed with the following error:\n\nThe task 'bar' was not handled in the plugins file. The following tasks are registered: return:arg, wait, create:long:file\n\nFix this in your plugins file here:\n${Cypress.config('pluginsFile')}\n\nhttps://on.cypress.io/api/task`);
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.task("bar")
|
||||
return cy.task("bar");
|
||||
});
|
||||
|
||||
it "throws after timing out", (done) ->
|
||||
Cypress.backend.resolves(Promise.delay(250))
|
||||
it("throws after timing out", function(done) {
|
||||
Cypress.backend.resolves(Promise.delay(250));
|
||||
|
||||
cy.on "fail", (err) =>
|
||||
lastLog = @lastLog
|
||||
cy.on("fail", err => {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
expect(@logs.length).to.eq(1)
|
||||
expect(lastLog.get("error")).to.eq(err)
|
||||
expect(lastLog.get("state")).to.eq("failed")
|
||||
expect(err.message).to.eq("`cy.task('foo')` timed out after waiting `50ms`.")
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task")
|
||||
done()
|
||||
expect(this.logs.length).to.eq(1);
|
||||
expect(lastLog.get("error")).to.eq(err);
|
||||
expect(lastLog.get("state")).to.eq("failed");
|
||||
expect(err.message).to.eq("`cy.task('foo')` timed out after waiting `50ms`.");
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task");
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.task("foo", null, { timeout: 50 })
|
||||
return cy.task("foo", null, { timeout: 50 });
|
||||
});
|
||||
|
||||
it "logs once on error", (done) ->
|
||||
Cypress.backend.rejects(new Error("task failed"))
|
||||
it("logs once on error", function(done) {
|
||||
Cypress.backend.rejects(new Error("task failed"));
|
||||
|
||||
cy.on "fail", (err) =>
|
||||
lastLog = @lastLog
|
||||
cy.on("fail", err => {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
expect(@logs.length).to.eq(1)
|
||||
expect(lastLog.get("error")).to.eq(err)
|
||||
expect(lastLog.get("state")).to.eq("failed")
|
||||
done()
|
||||
expect(this.logs.length).to.eq(1);
|
||||
expect(lastLog.get("error")).to.eq(err);
|
||||
expect(lastLog.get("state")).to.eq("failed");
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.task("foo")
|
||||
return cy.task("foo");
|
||||
});
|
||||
|
||||
it "can timeout from the backend's response", (done) ->
|
||||
err = new Error("timeout")
|
||||
err.timedOut = true
|
||||
it("can timeout from the backend's response", function(done) {
|
||||
const err = new Error("timeout");
|
||||
err.timedOut = true;
|
||||
|
||||
Cypress.backend.rejects(err)
|
||||
Cypress.backend.rejects(err);
|
||||
|
||||
cy.on "fail", (err) ->
|
||||
expect(err.message).to.include("`cy.task('wait')` timed out after waiting `100ms`.")
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task")
|
||||
done()
|
||||
cy.on("fail", function(err) {
|
||||
expect(err.message).to.include("`cy.task('wait')` timed out after waiting `100ms`.");
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task");
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.task("wait", null, { timeout: 100 })
|
||||
return cy.task("wait", null, { timeout: 100 });
|
||||
});
|
||||
|
||||
it "can really time out", (done) ->
|
||||
cy.on "fail", (err) ->
|
||||
expect(err.message).to.include("`cy.task('wait')` timed out after waiting `100ms`.")
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task")
|
||||
done()
|
||||
return it("can really time out", function(done) {
|
||||
cy.on("fail", function(err) {
|
||||
expect(err.message).to.include("`cy.task('wait')` timed out after waiting `100ms`.");
|
||||
expect(err.docsUrl).to.eq("https://on.cypress.io/task");
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.task("wait", null, { timeout: 100 })
|
||||
return cy.task("wait", null, { timeout: 100 });
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -1,269 +1,337 @@
|
||||
$ = Cypress.$.bind(Cypress)
|
||||
_ = Cypress._
|
||||
dom = Cypress.dom
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const $ = Cypress.$.bind(Cypress);
|
||||
const {
|
||||
_
|
||||
} = Cypress;
|
||||
const {
|
||||
dom
|
||||
} = Cypress;
|
||||
|
||||
helpers = require("../../support/helpers")
|
||||
const helpers = require("../../support/helpers");
|
||||
|
||||
describe "src/cy/commands/traversals", ->
|
||||
beforeEach ->
|
||||
cy.visit("/fixtures/dom.html")
|
||||
describe("src/cy/commands/traversals", function() {
|
||||
beforeEach(() => cy.visit("/fixtures/dom.html"));
|
||||
|
||||
fns = [
|
||||
{find: "*"}
|
||||
{filter: ":first"}
|
||||
{filter: (i) -> i == 0}
|
||||
{not: "div"}
|
||||
{not: (i, e) -> e.tagName == 'div'}
|
||||
{eq: 0}
|
||||
{closest: "body"}
|
||||
const fns = [
|
||||
{find: "*"},
|
||||
{filter: ":first"},
|
||||
{filter(i) { return i === 0; }},
|
||||
{not: "div"},
|
||||
{not(i, e) { return e.tagName === 'div'; }},
|
||||
{eq: 0},
|
||||
{closest: "body"},
|
||||
"children", "first", "last", "next", "nextAll", "nextUntil", "parent", "parents", "parentsUntil", "prev", "prevAll", "prevUntil", "siblings"
|
||||
]
|
||||
_.each fns, (fn) ->
|
||||
## normalize string vs object
|
||||
if _.isObject(fn)
|
||||
name = _.keys(fn)[0]
|
||||
arg = fn[name]
|
||||
else
|
||||
name = fn
|
||||
];
|
||||
_.each(fns, function(fn) {
|
||||
//# normalize string vs object
|
||||
let arg, name;
|
||||
if (_.isObject(fn)) {
|
||||
name = _.keys(fn)[0];
|
||||
arg = fn[name];
|
||||
} else {
|
||||
name = fn;
|
||||
}
|
||||
|
||||
context "##{name}", ->
|
||||
it "proxies through to jquery and returns new subject", ->
|
||||
el = cy.$$("#list")[name](arg)
|
||||
cy.get("#list")[name](arg).then ($el) ->
|
||||
expect($el).to.match el
|
||||
return context(`#${name}`, function() {
|
||||
it("proxies through to jquery and returns new subject", function() {
|
||||
const el = cy.$$("#list")[name](arg);
|
||||
return cy.get("#list")[name](arg).then($el => expect($el).to.match(el));
|
||||
});
|
||||
|
||||
describe "errors", ->
|
||||
beforeEach ->
|
||||
Cypress.config("defaultCommandTimeout", 100)
|
||||
describe("errors", function() {
|
||||
beforeEach(() => Cypress.config("defaultCommandTimeout", 100));
|
||||
|
||||
it "throws when options.length isnt a number", (done) ->
|
||||
cy.on "fail", (err) ->
|
||||
expect(err.message).to.include "You must provide a valid number to a `length` assertion. You passed: `asdf`"
|
||||
done()
|
||||
it("throws when options.length isnt a number", function(done) {
|
||||
cy.on("fail", function(err) {
|
||||
expect(err.message).to.include("You must provide a valid number to a `length` assertion. You passed: `asdf`");
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.get("#list")[name](arg).should("have.length", "asdf")
|
||||
return cy.get("#list")[name](arg).should("have.length", "asdf");
|
||||
});
|
||||
|
||||
it "throws on too many elements after timing out waiting for length", (done) ->
|
||||
el = cy.$$("#list")[name](arg)
|
||||
it("throws on too many elements after timing out waiting for length", function(done) {
|
||||
const el = cy.$$("#list")[name](arg);
|
||||
|
||||
node = dom.stringify cy.$$("#list"), "short"
|
||||
const node = dom.stringify(cy.$$("#list"), "short");
|
||||
|
||||
cy.on "fail", (err) ->
|
||||
expect(err.message).to.include "Too many elements found. Found '#{el.length}', expected '#{el.length - 1}'."
|
||||
done()
|
||||
cy.on("fail", function(err) {
|
||||
expect(err.message).to.include(`Too many elements found. Found '${el.length}', expected '${el.length - 1}'.`);
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.get("#list")[name](arg).should("have.length", el.length - 1)
|
||||
return cy.get("#list")[name](arg).should("have.length", el.length - 1);
|
||||
});
|
||||
|
||||
it "throws on too few elements after timing out waiting for length", (done) ->
|
||||
el = cy.$$("#list")[name](arg)
|
||||
it("throws on too few elements after timing out waiting for length", function(done) {
|
||||
const el = cy.$$("#list")[name](arg);
|
||||
|
||||
node = dom.stringify cy.$$("#list"), "short"
|
||||
const node = dom.stringify(cy.$$("#list"), "short");
|
||||
|
||||
cy.on "fail", (err) ->
|
||||
expect(err.message).to.include "Not enough elements found. Found '#{el.length}', expected '#{el.length + 1}'."
|
||||
done()
|
||||
cy.on("fail", function(err) {
|
||||
expect(err.message).to.include(`Not enough elements found. Found '${el.length}', expected '${el.length + 1}'.`);
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.get("#list")[name](arg).should("have.length", el.length + 1)
|
||||
return cy.get("#list")[name](arg).should("have.length", el.length + 1);
|
||||
});
|
||||
|
||||
it "without a dom element", (done) ->
|
||||
cy.on "fail", -> done()
|
||||
cy.noop({})[name](arg)
|
||||
it("without a dom element", function(done) {
|
||||
cy.on("fail", () => done());
|
||||
return cy.noop({})[name](arg);
|
||||
});
|
||||
|
||||
it "throws when subject is not in the document", (done) ->
|
||||
cy.on "command:end", =>
|
||||
cy.$$("#list").remove()
|
||||
it("throws when subject is not in the document", function(done) {
|
||||
cy.on("command:end", () => {
|
||||
return cy.$$("#list").remove();
|
||||
});
|
||||
|
||||
cy.on "fail", (err) ->
|
||||
expect(err.message).to.include "`cy.#{name}()` failed because this element"
|
||||
done()
|
||||
cy.on("fail", function(err) {
|
||||
expect(err.message).to.include(`\`cy.${name}()\` failed because this element`);
|
||||
return done();
|
||||
});
|
||||
|
||||
cy.get("#list")[name](arg)
|
||||
return cy.get("#list")[name](arg);
|
||||
});
|
||||
|
||||
it "returns no elements", (done) ->
|
||||
errIncludes = (el, node) =>
|
||||
node = dom.stringify cy.$$(node), "short"
|
||||
return it("returns no elements", function(done) {
|
||||
const errIncludes = (el, node) => {
|
||||
node = dom.stringify(cy.$$(node), "short");
|
||||
|
||||
cy.on "fail", (err) ->
|
||||
expect(err.message).to.include "Expected to find element: `#{el}`, but never found it. Queried from element: #{node}"
|
||||
done()
|
||||
return cy.on("fail", function(err) {
|
||||
expect(err.message).to.include(`Expected to find element: \`${el}\`, but never found it. Queried from element: ${node}`);
|
||||
return done();
|
||||
});
|
||||
};
|
||||
|
||||
switch name
|
||||
when "not"
|
||||
errIncludes(":checkbox", ":checkbox")
|
||||
cy.get(":checkbox").not(":checkbox")
|
||||
switch (name) {
|
||||
case "not":
|
||||
errIncludes(":checkbox", ":checkbox");
|
||||
return cy.get(":checkbox").not(":checkbox");
|
||||
|
||||
## these cannot error
|
||||
when "first", "last", "parentsUntil" then done()
|
||||
//# these cannot error
|
||||
case "first": case "last": case "parentsUntil": return done();
|
||||
|
||||
else
|
||||
errIncludes(".no-class-like-this-exists", "div:first")
|
||||
cy.get("div:first")[name](".no-class-like-this-exists")
|
||||
default:
|
||||
errIncludes(".no-class-like-this-exists", "div:first");
|
||||
return cy.get("div:first")[name](".no-class-like-this-exists");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe ".log", ->
|
||||
beforeEach ->
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
@lastLog = log
|
||||
return describe(".log", function() {
|
||||
beforeEach(function() {
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
return this.lastLog = log;
|
||||
});
|
||||
|
||||
return null
|
||||
return null;
|
||||
});
|
||||
|
||||
it "logs immediately before resolving", (done) ->
|
||||
cy.on "log:added", (attrs, log) ->
|
||||
if log.get("name") is name
|
||||
expect(log.pick("state")).to.deep.eq {
|
||||
it("logs immediately before resolving", function(done) {
|
||||
cy.on("log:added", function(attrs, log) {
|
||||
if (log.get("name") === name) {
|
||||
expect(log.pick("state")).to.deep.eq({
|
||||
state: "pending"
|
||||
}
|
||||
done()
|
||||
|
||||
cy.get("#list")[name](arg)
|
||||
|
||||
it "snapshots after finding element", ->
|
||||
cy.get("#list")[name](arg).then ->
|
||||
lastLog = @lastLog
|
||||
|
||||
expect(lastLog.get("snapshots").length).to.eq(1)
|
||||
expect(lastLog.get("snapshots")[0]).to.be.an("object")
|
||||
|
||||
it "has the $el", ->
|
||||
cy.get("#list")[name](arg).then ($el) ->
|
||||
lastLog = @lastLog
|
||||
|
||||
expect(lastLog.get("$el").get(0)).to.eq $el.get(0)
|
||||
|
||||
it "has a custom message", ->
|
||||
cy.get("#list")[name](arg).then ->
|
||||
if _.isUndefined(arg) or _.isFunction(arg)
|
||||
message = ""
|
||||
else
|
||||
message = arg.toString()
|
||||
|
||||
lastLog = @lastLog
|
||||
|
||||
expect(lastLog.get("message")).to.eq message
|
||||
|
||||
it "#consoleProps", ->
|
||||
cy.get("#list")[name](arg).then ($el) ->
|
||||
obj = {Command: name}
|
||||
if _.isFunction(arg)
|
||||
obj.Selector = ""
|
||||
else
|
||||
obj.Selector = [].concat(arg).join(", ")
|
||||
|
||||
yielded = Cypress.dom.getElements($el)
|
||||
|
||||
_.extend obj, {
|
||||
"Applied To": helpers.getFirstSubjectByName("get").get(0)
|
||||
Yielded: yielded
|
||||
Elements: $el.length
|
||||
});
|
||||
return done();
|
||||
}
|
||||
});
|
||||
|
||||
expect(@lastLog.invoke("consoleProps")).to.deep.eq obj
|
||||
return cy.get("#list")[name](arg);
|
||||
});
|
||||
|
||||
it "can be turned off", ->
|
||||
cy.get("#list")[name](arg, {log: false}).then ->
|
||||
lastLog = @lastLog
|
||||
it("snapshots after finding element", () => cy.get("#list")[name](arg).then(function() {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
expect(lastLog.get("name")).to.eq "get"
|
||||
expect(lastLog.get("snapshots").length).to.eq(1);
|
||||
return expect(lastLog.get("snapshots")[0]).to.be.an("object");
|
||||
}));
|
||||
|
||||
it "eventually resolves", ->
|
||||
cy.on "command:retry", _.after 2, ->
|
||||
cy.$$("button:first").text("foo").addClass("bar")
|
||||
it("has the $el", () => cy.get("#list")[name](arg).then(function($el) {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
cy.root().find("button:first").should("have.text", "foo").and("have.class", "bar")
|
||||
return expect(lastLog.get("$el").get(0)).to.eq($el.get(0));
|
||||
}));
|
||||
|
||||
it "retries until it finds", ->
|
||||
li = cy.$$("#list li:last")
|
||||
span = $("<span>foo</span>")
|
||||
it("has a custom message", () => cy.get("#list")[name](arg).then(function() {
|
||||
let message;
|
||||
if (_.isUndefined(arg) || _.isFunction(arg)) {
|
||||
message = "";
|
||||
} else {
|
||||
message = arg.toString();
|
||||
}
|
||||
|
||||
retry = _.after 3, ->
|
||||
li.append(span)
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
cy.on "command:retry", retry
|
||||
return expect(lastLog.get("message")).to.eq(message);
|
||||
}));
|
||||
|
||||
cy.get("#list li:last").find("span").then ($span) ->
|
||||
expect($span.get(0)).to.eq(span.get(0))
|
||||
it("#consoleProps", () => cy.get("#list")[name](arg).then(function($el) {
|
||||
const obj = {Command: name};
|
||||
if (_.isFunction(arg)) {
|
||||
obj.Selector = "";
|
||||
} else {
|
||||
obj.Selector = [].concat(arg).join(", ");
|
||||
}
|
||||
|
||||
it "retries until length equals n", ->
|
||||
buttons = cy.$$("button")
|
||||
const yielded = Cypress.dom.getElements($el);
|
||||
|
||||
length = buttons.length - 2
|
||||
_.extend(obj, {
|
||||
"Applied To": helpers.getFirstSubjectByName("get").get(0),
|
||||
Yielded: yielded,
|
||||
Elements: $el.length
|
||||
});
|
||||
|
||||
cy.on "command:retry", _.after 2, =>
|
||||
buttons.last().remove()
|
||||
buttons = cy.$$("button")
|
||||
return expect(this.lastLog.invoke("consoleProps")).to.deep.eq(obj);
|
||||
}));
|
||||
|
||||
## should resolving after removing 2 buttons
|
||||
cy.root().find("button").should("have.length", length).then ($buttons) ->
|
||||
expect($buttons.length).to.eq length
|
||||
return it("can be turned off", () => cy.get("#list")[name](arg, {log: false}).then(function() {
|
||||
const {
|
||||
lastLog
|
||||
} = this;
|
||||
|
||||
it "should('not.exist')", ->
|
||||
cy.on "command:retry", _.after 3, =>
|
||||
cy.$$("#nested-div").find("span").remove()
|
||||
return expect(lastLog.get("name")).to.eq("get");
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
cy.get("#nested-div").find("span").should("not.exist")
|
||||
it("eventually resolves", function() {
|
||||
cy.on("command:retry", _.after(2, () => cy.$$("button:first").text("foo").addClass("bar"))
|
||||
);
|
||||
|
||||
it "should('exist')", ->
|
||||
cy.on "command:retry", _.after 3, =>
|
||||
cy.$$("#nested-div").append($("<strong />"))
|
||||
return cy.root().find("button:first").should("have.text", "foo").and("have.class", "bar");
|
||||
});
|
||||
|
||||
cy.get("#nested-div").find("strong")
|
||||
it("retries until it finds", function() {
|
||||
const li = cy.$$("#list li:last");
|
||||
const span = $("<span>foo</span>");
|
||||
|
||||
## https://github.com/cypress-io/cypress/issues/38
|
||||
it "works with checkboxes", ->
|
||||
cy.on "command:retry", _.after 2, =>
|
||||
c = cy.$$("[name=colors]").slice(0, 2)
|
||||
c.prop("checked", true)
|
||||
const retry = _.after(3, () => li.append(span));
|
||||
|
||||
cy.get("#by-name").find(":checked").should("have.length", 2)
|
||||
cy.on("command:retry", retry);
|
||||
|
||||
it "does not log using first w/options", ->
|
||||
logs = []
|
||||
return cy.get("#list li:last").find("span").then($span => expect($span.get(0)).to.eq(span.get(0)));
|
||||
});
|
||||
|
||||
cy.on "log:added", (attrs, log) ->
|
||||
if attrs.name isnt "assert"
|
||||
logs.push(log)
|
||||
it("retries until length equals n", function() {
|
||||
let buttons = cy.$$("button");
|
||||
|
||||
cy.get("button").first({log: false}).then ($button) ->
|
||||
expect($button.length).to.eq(1)
|
||||
expect(logs.length).to.eq(1)
|
||||
const length = buttons.length - 2;
|
||||
|
||||
describe "errors", ->
|
||||
beforeEach ->
|
||||
Cypress.config("defaultCommandTimeout", 100)
|
||||
cy.on("command:retry", _.after(2, () => {
|
||||
buttons.last().remove();
|
||||
return buttons = cy.$$("button");
|
||||
})
|
||||
);
|
||||
|
||||
@logs = []
|
||||
//# should resolving after removing 2 buttons
|
||||
return cy.root().find("button").should("have.length", length).then($buttons => expect($buttons.length).to.eq(length));
|
||||
});
|
||||
|
||||
cy.on "log:added", (attrs, log) =>
|
||||
@logs.push(log)
|
||||
it("should('not.exist')", function() {
|
||||
cy.on("command:retry", _.after(3, () => {
|
||||
return cy.$$("#nested-div").find("span").remove();
|
||||
})
|
||||
);
|
||||
|
||||
return null
|
||||
return cy.get("#nested-div").find("span").should("not.exist");
|
||||
});
|
||||
|
||||
it "errors after timing out not finding element", (done) ->
|
||||
cy.on "fail", (err) ->
|
||||
expect(err.message).to.include "Expected to find element: `span`, but never found it. Queried from element: <li.item>"
|
||||
done()
|
||||
it("should('exist')", function() {
|
||||
cy.on("command:retry", _.after(3, () => {
|
||||
return cy.$$("#nested-div").append($("<strong />"));
|
||||
})
|
||||
);
|
||||
|
||||
cy.get("#list li:last").find("span")
|
||||
return cy.get("#nested-div").find("strong");
|
||||
});
|
||||
|
||||
it "throws once when incorrect sizzle selector", (done) ->
|
||||
cy.on "fail", (err) =>
|
||||
expect(@logs.length).to.eq 2
|
||||
done()
|
||||
//# https://github.com/cypress-io/cypress/issues/38
|
||||
it("works with checkboxes", function() {
|
||||
cy.on("command:retry", _.after(2, () => {
|
||||
const c = cy.$$("[name=colors]").slice(0, 2);
|
||||
return c.prop("checked", true);
|
||||
})
|
||||
);
|
||||
|
||||
cy.get("div:first").find(".spinner'")
|
||||
return cy.get("#by-name").find(":checked").should("have.length", 2);
|
||||
});
|
||||
|
||||
it "logs out $el when existing $el is found even on failure", (done) ->
|
||||
button = cy.$$("#button").hide()
|
||||
it("does not log using first w/options", function() {
|
||||
const logs = [];
|
||||
|
||||
cy.on "fail", (err) =>
|
||||
log = @logs[1]
|
||||
cy.on("log:added", function(attrs, log) {
|
||||
if (attrs.name !== "assert") {
|
||||
return logs.push(log);
|
||||
}
|
||||
});
|
||||
|
||||
expect(log.get("state")).to.eq("failed")
|
||||
expect(err.message).to.include(log.get("error").message)
|
||||
expect(log.get("$el").get(0)).to.eq button.get(0)
|
||||
return cy.get("button").first({log: false}).then(function($button) {
|
||||
expect($button.length).to.eq(1);
|
||||
return expect(logs.length).to.eq(1);
|
||||
});
|
||||
});
|
||||
|
||||
consoleProps = log.invoke("consoleProps")
|
||||
expect(consoleProps.Yielded).to.eq button.get(0)
|
||||
expect(consoleProps.Elements).to.eq button.length
|
||||
done()
|
||||
return describe("errors", function() {
|
||||
beforeEach(function() {
|
||||
Cypress.config("defaultCommandTimeout", 100);
|
||||
|
||||
cy.get("#dom").find("#button").should("be.visible")
|
||||
this.logs = [];
|
||||
|
||||
cy.on("log:added", (attrs, log) => {
|
||||
return this.logs.push(log);
|
||||
});
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
it("errors after timing out not finding element", function(done) {
|
||||
cy.on("fail", function(err) {
|
||||
expect(err.message).to.include("Expected to find element: `span`, but never found it. Queried from element: <li.item>");
|
||||
return done();
|
||||
});
|
||||
|
||||
return cy.get("#list li:last").find("span");
|
||||
});
|
||||
|
||||
it("throws once when incorrect sizzle selector", function(done) {
|
||||
cy.on("fail", err => {
|
||||
expect(this.logs.length).to.eq(2);
|
||||
return done();
|
||||
});
|
||||
|
||||
return cy.get("div:first").find(".spinner'");
|
||||
});
|
||||
|
||||
return it("logs out $el when existing $el is found even on failure", function(done) {
|
||||
const button = cy.$$("#button").hide();
|
||||
|
||||
cy.on("fail", err => {
|
||||
const log = this.logs[1];
|
||||
|
||||
expect(log.get("state")).to.eq("failed");
|
||||
expect(err.message).to.include(log.get("error").message);
|
||||
expect(log.get("$el").get(0)).to.eq(button.get(0));
|
||||
|
||||
const consoleProps = log.invoke("consoleProps");
|
||||
expect(consoleProps.Yielded).to.eq(button.get(0));
|
||||
expect(consoleProps.Elements).to.eq(button.length);
|
||||
return done();
|
||||
});
|
||||
|
||||
return cy.get("#dom").find("#button").should("be.visible");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user