Skip to content

test: make sure all components can be created with document.createEle…#34977

Merged
marchbox merged 4 commits intomicrosoft:masterfrom
marchbox:users/machi/test-createelement
Aug 7, 2025
Merged

test: make sure all components can be created with document.createEle…#34977
marchbox merged 4 commits intomicrosoft:masterfrom
marchbox:users/machi/test-createelement

Conversation

@marchbox
Copy link
Copy Markdown
Contributor

@marchbox marchbox commented Aug 6, 2025

Previous Behavior

No tests to make sure components can be created with document.createElement().

New Behavior

Added tests.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 6, 2025

📊 Bundle size report

✅ No changes found

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 6, 2025

Pull request demo site: URL

@marchbox marchbox enabled auto-merge (squash) August 6, 2025 00:29
@radium-v
Copy link
Copy Markdown
Contributor

radium-v commented Aug 6, 2025

Should this instead create the element and insert it onto the page, then expect it to be attached?

test('should create with `document.createElement()`', async ({ fastPage, page }) => {
    const { element } = fastPage;

    await fastPage.setTemplate('');

    await page.evaluate(() => {
      const node = document.createElement('fluent-accordion-item');
      document.body.append(node);
    });

    await expect(element).toBeAttached();
  });

@radium-v radium-v disabled auto-merge August 6, 2025 00:39
@marchbox
Copy link
Copy Markdown
Contributor Author

marchbox commented Aug 6, 2025

Should this instead create the element and insert it onto the page, then expect it to be attached?

test('should create with `document.createElement()`', async ({ fastPage, page }) => {
    const { element } = fastPage;

    await fastPage.setTemplate('');

    await page.evaluate(() => {
      const node = document.createElement('fluent-accordion-item');
      document.body.append(node);
    });

    await expect(element).toBeAttached();
  });

@radium-v That will not catch this particular issue, because if the JS class has code to modify attribute (e.g. by calling this.setAttribute()) in constructor, the browser will emit error, but the element will still be successfully created and can be attached to document.body. This test is to make sure browser doesn't throw any error from the document.createElement() call. Another weird thing is that this error can not be caught inside a try...catch, apparently as per the spec: https://issues.chromium.org/issues/382473086.

@marchbox marchbox merged commit 5c53634 into microsoft:master Aug 7, 2025
15 checks passed
@marchbox marchbox deleted the users/machi/test-createelement branch August 7, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants