Skip to content

Commit

Permalink
Fix filtering by index (closes DevExpress#1240)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderMoskovkin committed Feb 22, 2017
1 parent 687dc18 commit 76b3b7e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/client-functions/selector-builder/add-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ const SNAPSHOT_PROPERTIES = NODE_SNAPSHOT_PROPERTIES.concat(ELEMENT_SNAPSHOT_PRO


var filterNodes = (new ClientFunctionBuilder((nodes, filter, querySelectorRoot, originNode) => {
if (typeof filter === 'number')
return filter < 0 ? [nodes[nodes.length + filter]] : [nodes[filter]];
if (typeof filter === 'number') {
var matchingNode = filter < 0 ? nodes[nodes.length + filter] : nodes[filter];

return matchingNode ? [matchingNode] : [];
}

var result = [];

Expand Down
11 changes: 11 additions & 0 deletions test/functional/fixtures/regression/gh-1240/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>GH-1240</title>
</head>
<body>
<div id="div">
<span>Span</span>
</div>
</body>
</html>
5 changes: 5 additions & 0 deletions test/functional/fixtures/regression/gh-1240/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('[Regression](GH-1240)', function () {
it('Test should not raise an error when try to get a non-existent child', function () {
return runTests('testcafe-fixtures/index-test.js', 'Check a non-existent child', { only: ['chrome'] });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Selector } from 'testcafe';

fixture `gh-1240`
.page `file://d:/git/testcafe/test/functional/fixtures/regression/gh-1240/pages/index.html`;

test('Check a non-existent child', async t => {
const span = Selector('#div').child(2);

await t.expect(span.exists).notOk();
});

0 comments on commit 76b3b7e

Please sign in to comment.