From ab9924cb5aee7af70831518c162a161e2007e098 Mon Sep 17 00:00:00 2001 From: Brian Mann Date: Thu, 31 Aug 2017 23:05:41 -0400 Subject: [PATCH] driver: add test for cy.within callback context, remove unnecessary ensureDom check --- packages/driver/src/cy/commands/querying.coffee | 4 ++-- .../test/cypress/integration/commands/querying_spec.coffee | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/driver/src/cy/commands/querying.coffee b/packages/driver/src/cy/commands/querying.coffee index 75d23676e5..df10a9a374 100644 --- a/packages/driver/src/cy/commands/querying.coffee +++ b/packages/driver/src/cy/commands/querying.coffee @@ -418,7 +418,7 @@ module.exports = (Commands, Cypress, cy, state, config) -> Commands.addAll({ prevSubject: "dom"}, { within: (subject, options, fn) -> - cy.ensureDom(subject) + ctx = @ if _.isUndefined(fn) fn = options @@ -447,7 +447,7 @@ module.exports = (Commands, Cypress, cy, state, config) -> prevWithinSubject = cy.state("withinSubject") cy.state("withinSubject", subject) - fn.call cy.state("runnable").ctx, subject + fn.call(ctx, subject) cleanup = -> cy.removeListener("command:start", setWithinSubject) diff --git a/packages/driver/test/cypress/integration/commands/querying_spec.coffee b/packages/driver/test/cypress/integration/commands/querying_spec.coffee index 89b1d3f77b..54445e7052 100644 --- a/packages/driver/test/cypress/integration/commands/querying_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/querying_spec.coffee @@ -219,6 +219,12 @@ describe "src/cy/commands/querying", -> cy.focused().should("have.class", "focused") context "#within", -> + it "invokes callback function with runnable.ctx", -> + ctx = @ + + cy.get("div:first").within -> + expect(ctx is @).to.be.true + it "scopes additional GET finders to the subject", -> input = cy.$$("#by-name input:first")