MCPcopy Create free account
hub / github.com/BrainicHQ/DoHSpeedTest / createElement

Function createElement

tests/settings-persistence.test.mjs:23–63  ·  view source on GitHub ↗
(id = '')

Source from the content-addressed store, hash-verified

21}
22
23function createElement(id = '') {
24 const listeners = new Map();
25 const element = {
26 id,
27 dataset: {},
28 style: {},
29 classList: createClassList(),
30 children: [],
31 parentElement: { style: {} },
32 nextElementSibling: null,
33 disabled: false,
34 value: '',
35 textContent: '',
36 addEventListener: function (type, handler) {
37 if (!listeners.has(type)) listeners.set(type, []);
38 listeners.get(type).push(handler);
39 },
40 click: function () {
41 (listeners.get('click') || []).forEach(handler => handler({ target: this }));
42 },
43 append: function (...children) { this.children.push(...children); },
44 appendChild: function (child) { this.children.push(child); return child; },
45 remove: () => {},
46 setAttribute: () => {},
47 focus: () => {},
48 querySelector: () => null,
49 querySelectorAll: () => [],
50 getContext: () => ({})
51 };
52
53 let innerHTML = '';
54 Object.defineProperty(element, 'innerHTML', {
55 get: () => innerHTML,
56 set: value => {
57 innerHTML = value;
58 element.children = [];
59 }
60 });
61
62 return element;
63}
64
65function createHarness(seed = {}) {
66 const storage = new Map(Object.entries(seed));

Callers 1

createHarnessFunction · 0.70

Calls 1

createClassListFunction · 0.70

Tested by

no test coverage detected