github.com/outbrain/consul@v1.4.5/ui-v2/tests/unit/utils/dom/click-first-anchor-test.js (about) 1 import domClickFirstAnchor from 'consul-ui/utils/dom/click-first-anchor'; 2 import { module, test } from 'qunit'; 3 4 module('Unit | Utility | dom/click first anchor'); 5 6 test('it does nothing if the clicked element is generally a clickable thing', function(assert) { 7 const closest = function() { 8 return { 9 querySelector: function() { 10 assert.ok(false); 11 }, 12 }; 13 }; 14 const click = domClickFirstAnchor(closest); 15 ['INPUT', 'LABEL', 'A', 'Button'].forEach(function(item) { 16 const expected = null; 17 const actual = click({ 18 target: { 19 nodeName: item, 20 }, 21 }); 22 assert.equal(actual, expected); 23 }); 24 }); 25 test("it does nothing if an anchor isn't found", function(assert) { 26 const closest = function() { 27 return { 28 querySelector: function() { 29 return null; 30 }, 31 }; 32 }; 33 const click = domClickFirstAnchor(closest); 34 const expected = null; 35 const actual = click({ 36 target: { 37 nodeName: 'DIV', 38 }, 39 }); 40 assert.equal(actual, expected); 41 }); 42 test('it dispatches the result of `click` if an anchor is found', function(assert) { 43 assert.expect(1); 44 const expected = 'click'; 45 const closest = function() { 46 return { 47 querySelector: function() { 48 return { 49 dispatchEvent: function(ev) { 50 const actual = ev.type; 51 assert.equal(actual, expected); 52 }, 53 }; 54 }, 55 }; 56 }; 57 const click = domClickFirstAnchor(closest); 58 click({ 59 target: { 60 nodeName: 'DIV', 61 }, 62 }); 63 });