github.com/outbrain/consul@v1.4.5/ui-v2/tests/unit/utils/get-component-factory-test.js (about) 1 import getComponentFactory from 'consul-ui/utils/get-component-factory'; 2 import { module, test } from 'qunit'; 3 4 module('Unit | Utility | get component factory'); 5 6 test("it uses lookup to locate the instance of the component based on the DOM element's id", function(assert) { 7 const expected = 'name'; 8 let getComponent = getComponentFactory({ 9 lookup: function() { 10 return { id: expected }; 11 }, 12 }); 13 assert.equal(typeof getComponent, 'function', 'returns a function'); 14 const actual = getComponent({ 15 getAttribute: function(name) { 16 return 'id'; 17 }, 18 }); 19 assert.equal(actual, expected, 'performs a lookup based on the id'); 20 }); 21 test("it returns null if it can't find it", function(assert) { 22 const expected = null; 23 let getComponent = getComponentFactory({ 24 lookup: function() { 25 return { id: '' }; 26 }, 27 }); 28 const actual = getComponent({ 29 getAttribute: function(name) { 30 return 'non-existent'; 31 }, 32 }); 33 assert.equal(actual, expected); 34 }); 35 test('it returns null if there is no id', function(assert) { 36 const expected = null; 37 let getComponent = getComponentFactory({ 38 lookup: function() { 39 return { id: '' }; 40 }, 41 }); 42 const actual = getComponent({ 43 getAttribute: function(name) { 44 return; 45 }, 46 }); 47 assert.equal(actual, expected); 48 });