Skip to content

fix(mock-doc): add File global for tests#6744

Open
srikarphanikumar wants to merge 1 commit into
stenciljs:mainfrom
srikarphanikumar:fix/mock-file-global-testing
Open

fix(mock-doc): add File global for tests#6744
srikarphanikumar wants to merge 1 commit into
stenciljs:mainfrom
srikarphanikumar:fix/mock-file-global-testing

Conversation

@srikarphanikumar
Copy link
Copy Markdown

What is the current behavior?

Stencil's mock DOM test environment exposes browser-like globals such as Event, Request, and Response, but it does not expose File.

As a result, unit tests that construct a browser File object can fail with ReferenceError: File is not defined.

GitHub Issue Number: #3539

What is the new behavior?

Adds a mock File constructor to Stencil's mock DOM globals.

This allows Stencil unit tests to call new File(...) in the test environment, including after rendering with newSpecPage().

The PR also adds regression coverage for:

  • File being available on the test global and window
  • constructing a File with name, type, lastModified, and size
  • constructing a File after rendering a spec page

Documentation

N/A

Does this introduce a breaking change?

  • Yes
  • No

Testing

  • npm run prettier.base -- --check src/mock-doc/file.ts src/mock-doc/global.ts src/mock-doc/index.ts src/mock-doc/test/global.spec.ts src/testing/test/functional.spec.tsx
  • npx eslint src/mock-doc/file.ts src/mock-doc/global.ts src/mock-doc/index.ts src/mock-doc/test/global.spec.ts src/testing/test/functional.spec.tsx
  • npm run tsc.prod

Other information

Fixes #3539.

@srikarphanikumar srikarphanikumar requested a review from a team as a code owner June 2, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReferenceError: File is not defined on Unit Test

1 participant