From 4534e86f622be594f6b3379efff11dee0b2474d8 Mon Sep 17 00:00:00 2001 From: Marcy Sutton Date: Mon, 10 Jul 2017 14:57:24 -0700 Subject: [PATCH] fix: pass virtualNode to Rule.run Closes https://github.com/dequelabs/axe-core/issues/394 --- lib/core/base/rule.js | 2 +- test/core/base/rule.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/core/base/rule.js b/lib/core/base/rule.js index 35168a8cec..44ed7e4e3c 100644 --- a/lib/core/base/rule.js +++ b/lib/core/base/rule.js @@ -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})); diff --git a/test/core/base/rule.js b/test/core/base/rule.js index 92138cc004..d1b58b4fa2 100644 --- a/test/core/base/rule.js +++ b/test/core/base/rule.js @@ -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) {