-
Notifications
You must be signed in to change notification settings - Fork 159
feat(within): Support cy.within #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,8 @@ | |
| "contributions": [ | ||
| "code", | ||
| "doc", | ||
| "ideas" | ||
| "ideas", | ||
| "test" | ||
| ] | ||
| } | ||
| ], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,8 @@ | |
| "test": "npm-run-all --parallel test:unit test:cypress", | ||
| "test:unit": "kcd-scripts test --no-watch", | ||
| "test:unit:watch": "kcd-scripts test", | ||
| "test:cypress:serve": "serve -l 13370 ./cypress/fixtures/test-app", | ||
| "test:cypress:run": "cypress run", | ||
| "test:cypress:serve": "serve --listen 13370 ./cypress/fixtures/test-app", | ||
| "test:cypress:run": "wait-port --timeout 10000 localhost:13370 && cypress run", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| "test:cypress:open": "cypress open", | ||
| "test:cypress": "npm-run-all --silent --parallel --race test:cypress:serve test:cypress:run", | ||
| "test:cypress:dev": "npm-run-all --silent --parallel --race test:cypress:serve test:cypress:open", | ||
|
|
@@ -45,7 +45,8 @@ | |
| "cypress": "^3.0.1", | ||
| "kcd-scripts": "^0.37.0", | ||
| "npm-run-all": "^4.1.2", | ||
| "serve": "^7.2.0" | ||
| "serve": "^7.2.0", | ||
| "wait-port": "^0.2.2" | ||
| }, | ||
| "peerDependencies": { | ||
| "cypress": "^2.1.0 || ^3.0.0" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import {queries, waitForElement} from 'dom-testing-library' | ||
| import {getContainer} from './support/utils' | ||
|
||
|
|
||
| const defaults = { | ||
| timeout: 3000, | ||
|
|
@@ -14,10 +15,12 @@ const commands = Object.keys(queries).map(queryName => { | |
| : defaults | ||
|
|
||
| const queryImpl = queries[queryName] | ||
| const baseCommandImpl = doc => | ||
| waitForElement(() => queryImpl(doc, ...args), Object.assign({}, waitOptions, { | ||
| container: doc, | ||
| const baseCommandImpl = doc => { | ||
| const container = getContainer(cy, waitOptions.container || doc); | ||
| return waitForElement(() => queryImpl(container, ...args), Object.assign({}, waitOptions, { | ||
| container, | ||
| })) | ||
| } | ||
| let commandImpl | ||
| if ( | ||
| queryName.startsWith('queryBy') || | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| function getElement(element) { | ||
|
||
| if (Cypress.dom.isJquery(element)) { | ||
| return element.get(0) | ||
| } | ||
| return element | ||
| } | ||
|
|
||
| function getContainer(cy, container) { | ||
|
||
| const withinContainer = cy.state('withinSubject') | ||
| if (withinContainer) { | ||
| return getElement(withinContainer) | ||
| } | ||
| return getElement(container) | ||
| } | ||
|
|
||
| export { | ||
| getElement, | ||
| getContainer, | ||
| } | ||
|
|
||
| /* globals Cypress */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear from the documentation https://docs.cypress.io/api/commands/then.html#DOM-element , but as I remember,
.thencallback gets a jQuery collection in its first argument, not a single DOM element. Could you please verify this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, you use
Cypress.dom.isJquery(element)to accept both jQuery collection and a single element as the container. This wasn't the case before, so likely requires a documentation update where thecontaineroption type is described.