Skip to content

Conversation

@janhoogeveen
Copy link
Contributor

πŸ”— Linked issue

Resolves #228

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

The helper method is initialized as an empty object as a fallback when the helper does not exist on the window object. Later in the code, it's expected that the helper has working methods. This seems to work fine when running a Nuxt app, but not in Vitest.

In this fix I add no-ops and optional chaining to prevent x is not defined on y errors.

@netlify
Copy link

netlify bot commented Sep 26, 2025

βœ… Deploy Preview for nuxt-color-mode canceled.

Name Link
πŸ”¨ Latest commit 00e1dc8
πŸ” Latest deploy log https://app.netlify.com/projects/nuxt-color-mode/deploys/69135a01c567b800085c4184

Copy link
Collaborator

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that this is only relevant for testing, how about we guard this with if (import.meta.test)?

that way we don't add to the production bundle

@danielroe danielroe changed the title fix: Stub helper utility with no-ops if it doesn't exist on the window object fix: stub helper utility with no-ops in test mode Nov 11, 2025
@danielroe danielroe merged commit 323454b into nuxt-modules:main Nov 11, 2025
5 checks passed
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.

helper.getColorScheme is not a function error when trying to use the module

2 participants