Skip to content

Commit

Permalink
Pass options to derivative selectors (fixes DevExpress#1907)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderMoskovkin committed Oct 23, 2017
1 parent edc8b48 commit 2f85f34
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/client-functions/selectors/add-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,17 @@ function createDerivativeSelectorWithFilter (getSelector, SelectorBuilder, selec
filterNodes: filterNodes
};

var { boundTestRun, timeout, visibilityCheck } = collectionModeSelectorBuilder.options;

dependencies = assign(dependencies, additionalDependencies);

var builder = new SelectorBuilder(selectorFn, {
dependencies,
customDOMProperties,
customMethods
customMethods,
boundTestRun,
timeout,
visibilityCheck
}, { instantiation: 'Selector' });

return builder.getFunction();
Expand Down
22 changes: 22 additions & 0 deletions test/functional/fixtures/regression/gh-1907/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>gh-1907</title>
</head>
<body>
<div></div>
<div id="div">div
<div id="child">child</div>
</div>
<div></div>

<div id="delay" style="display: none;">Appears after delay</div>
<div id="hidden" style="display: none">Hidden</div>

<script>
window.setTimeout(function (){
document.querySelector('#delay').style.display = 'block';
}, 1000);
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions test/functional/fixtures/regression/gh-1907/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var expect = require('chai').expect;

describe('[Regression](GH-1907)', function () {
it('Base selector should pass the boundTestRun option to derivative selectors', function () {
return runTests('testcafe-fixtures/index-test.js', 'Check boundTestRun');
});

it('Base selector should pass timeout and visibilityCheck options to derivative selectors', function () {
return runTests('testcafe-fixtures/index-test.js', 'Check timeout and visibilityCheck', {
selectorTimeout: 0,
shouldFail: true
})
.catch(function (errs) {
expect(errs[0]).contains('Cannot obtain information about the node because the specified selector does not match any node in the DOM tree.');
expect(errs[0]).contains('> 40 | await t.expect(div.textContent).eql(\'Hidden\');');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fs from 'fs';
import { Selector } from 'testcafe';

fixture `GH-1907`
.page `http://localhost:3000/fixtures/regression/gh-1907/pages/index.html`;

test('Check boundTestRun', async t => {
const div = Selector('#div', { boundTestRun: t });

return new Promise((resolve, reject) => {
fs.readFile('not/exists', async () => {
try {
await t
.expect(div.nth(0).exists).ok()
.expect(div.withText('div').exists).ok()
.expect(div.withAttribute('id', 'div').exists).ok()
.expect(div.filter(() => true).exists).ok()
.expect(div.find('#child').exists).ok()
.expect(div.parent().exists).ok()
.expect(div.child().exists).ok()
.expect(div.sibling().exists).ok()
.expect(div.nextSibling().exists).ok()
.expect(div.prevSibling().exists).ok();
}
catch (err) {
reject(err);
return;
}

resolve();
});
});
});

test('Check timeout and visibilityCheck', async t => {
await t.click(Selector('#delay', { timeout: 2000 }).withText('Appears after delay'));

const div = Selector('#hidden', { visibilityCheck: true }).withText('Hidden');

await t.expect(div.textContent).eql('Hidden');
});

0 comments on commit 2f85f34

Please sign in to comment.