| 242 | type MockElementInternals = Record<keyof ElementInternals, null>; |
| 243 | |
| 244 | export class MockElement extends MockNode { |
| 245 | __namespaceURI: string | null; |
| 246 | __attributeMap: MockAttributeMap | null | undefined; |
| 247 | __shadowRoot: ShadowRoot | null | undefined; |
| 248 | __style: MockCSSStyleDeclaration | null | undefined; |
| 249 | |
| 250 | attachInternals(): MockElementInternals { |
| 251 | return new Proxy({} as unknown as MockElementInternals, { |
| 252 | get: function (_target, prop, _receiver) { |
| 253 | /** |
| 254 | * only print warning when running in a test environment |
| 255 | */ |
| 256 | if ('process' in globalThis && globalThis.process.env.__STENCIL_SPEC_TESTS__) { |
| 257 | console.error( |
| 258 | `NOTE: Property ${String(prop)} was accessed on ElementInternals, but this property is not implemented. |
| 259 | Testing components with ElementInternals is fully supported in e2e tests.`, |
| 260 | ); |
| 261 | } |
| 262 | }, |
| 263 | }); |
| 264 | } |
| 265 | |
| 266 | constructor(ownerDocument: any, nodeName: string | null, namespaceURI: string | null = null) { |
| 267 | super(ownerDocument, NODE_TYPES.ELEMENT_NODE, typeof nodeName === 'string' ? nodeName : null, null); |
| 268 | this.__namespaceURI = namespaceURI; |
| 269 | this.__shadowRoot = null; |
| 270 | this.__attributeMap = null; |
| 271 | } |
| 272 | |
| 273 | override addEventListener(type: string, handler: (ev?: any) => void) { |
| 274 | addEventListener(this, type, handler); |
| 275 | } |
| 276 | |
| 277 | attachShadow(_opts: ShadowRootInit) { |
| 278 | const shadowRoot = this.ownerDocument.createDocumentFragment(); |
| 279 | shadowRoot.delegatesFocus = _opts.delegatesFocus ?? false; |
| 280 | this.shadowRoot = shadowRoot; |
| 281 | return shadowRoot; |
| 282 | } |
| 283 | |
| 284 | blur() { |
| 285 | // Prevent infinite recursion when blur event handlers call blur() |
| 286 | // on the same element while it's already processing a blur event |
| 287 | if (isCurrentlyDispatching(this, 'blur')) { |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | markAsDispatching(this, 'blur'); |
| 292 | try { |
| 293 | dispatchEvent( |
| 294 | this, |
| 295 | new MockFocusEvent('blur', { relatedTarget: null, bubbles: true, cancelable: true, composed: true }), |
| 296 | ); |
| 297 | } finally { |
| 298 | unmarkAsDispatching(this, 'blur'); |
| 299 | } |
| 300 | } |
| 301 |
nothing calls this directly
no outgoing calls
no test coverage detected