Skip to content

Commit

Permalink
fix incorrect selector chain message when with method is used (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed Jun 11, 2019
1 parent 172d84d commit 1c67679
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/client-functions/client-function-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@ export default class ClientFunctionBuilder {
clientFn[functionBuilderSymbol] = this;

clientFn.with = options => {
if (typeof options === 'object')
options = assign({}, this.options, options);
return this._getClientFnWithOverriddenOptions(options);
};
}

const builder = new this.constructor(this.fn, options, {
instantiation: 'with',
execution: this.callsiteNames.execution
});
_getClientFnWithOverriddenOptions (options) {
if (typeof options === 'object')
options = assign({}, this.options, options);

return builder.getFunction();
};
const builder = new this.constructor(this.fn, options, {
instantiation: 'with',
execution: this.callsiteNames.execution
});

return builder.getFunction();
}

getBoundTestRun () {
Expand Down
4 changes: 4 additions & 0 deletions src/client-functions/selectors/selector-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ export default class SelectorBuilder extends ClientFunctionBuilder {
addAPI(selectorFn, () => selectorFn, SelectorBuilder, this.options.customDOMProperties, this.options.customMethods);
}

_getClientFnWithOverriddenOptions (options) {
return super._getClientFnWithOverriddenOptions(Object.assign(options, { apiFn: null }));
}

_processResult (result, selectorArgs) {
const snapshot = super._processResult(result, selectorArgs);

Expand Down
11 changes: 11 additions & 0 deletions test/functional/fixtures/regression/gh-2568/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,15 @@ describe('[Regression](GH-2568)', function () {
`);
});
});

it('with', function () {
return runTests('testcafe-fixtures/index.js', 'with', { selectorTimeout: 100, shouldFail: true })
.catch(function (errs) {
assertSelectorCallstack(errs[0], `
The specified selector does not match any element in the DOM tree.
> | Selector('non-existing-element')
| .find('ul')
`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,7 @@ test('custom methods', async t => {

await t.click(selector);
});

test('with', async t => {
await t.click(Selector('non-existing-element').with({ timeout: 100 }).find('ul'));
});

0 comments on commit 1c67679

Please sign in to comment.