Skip to content

Commit

Permalink
Merge pull request #8 from JaySunSyn/refactor-query
Browse files Browse the repository at this point in the history
Fiz nth
  • Loading branch information
JaySunSyn authored May 3, 2019
2 parents 78e3b58 + 7423983 commit bc16724
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Cypress.Commands.overwrite('get', (originalFn, selector, options) => {

return cy.window({log: false}).then((w) => new Cypress.Promise((resolve, reject) => {
const walker = new Daywalker(w);

const result = options && options.all
? walker.querySelectorAll(selector)
: walker.querySelector(selector, (options && options.nth) || 0);
: walker.querySelector(selector, (options && options.nth) || 1);
if (result != null) {
resolve(result);
return true;
Expand Down
4 changes: 2 additions & 2 deletions daywalker-store-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class DaywalkerStoreQuery {
return result;
}

querySelector(selector, nth = 0) {
querySelector(selector, nth = 1) {
const result = this.queryStore(selector);
if (Array.isArray(result)) {
return result.length > nth ? result[nth] : null;
return result.length >= nth ? result[nth - 1] : null;
}
return result;
}
Expand Down

0 comments on commit bc16724

Please sign in to comment.