Skip to content

Commit

Permalink
fix: pass virtualNode to Rule.run
Browse files Browse the repository at this point in the history
Closes #394
  • Loading branch information
Marcy Sutton committed Jul 13, 2017
1 parent 3087e90 commit 4534e86
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Rule.prototype.run = function (context, options, resolve, reject) {
try {
// Matches throws an error when it lacks support for document methods
nodes = this.gather(context)
.filter(node => this.matches(node.actualNode));
.filter(node => this.matches(node.actualNode, node));
} catch (error) {
// Exit the rule execution if matches fails
reject(new SupportError({cause: error, ruleId: this.id}));
Expand Down
19 changes: 19 additions & 0 deletions test/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,26 @@ describe('Rule', function() {
assert.isTrue(success);
done();
}, isNotCalled);
});

it('should pass a virtualNode to #matches', function(done) {
var div = document.createElement('div');
fixture.appendChild(div);
var success = false,
rule = new Rule({
matches: function(node, virtualNode) {
assert.equal(virtualNode.actualNode, div);
success = true;
return [];
}
});

rule.run({
include: [axe.utils.getFlattenedTree(div)[0]]
}, {}, function() {
assert.isTrue(success);
done();
}, isNotCalled);
});

it('should handle an error in #matches', function(done) {
Expand Down

0 comments on commit 4534e86

Please sign in to comment.