[BUG] Vue 3 Component Test Error: "ReferenceError: Item is not defined"
See original GitHub issueContext:
- Playwright Version: 1.27.1
- Operating System: Windows
- Node.js version: 16.17.0
- Browser: All
- Extra: Vite, Vue 3
playwright test -c playwright-ct.config.ts
Hi, I have just migrated from Cypress to Playwright and have encountered a similar issue to https://github.com/microsoft/playwright/issues/17957 in Vue 3.
I’m defining an item type from withing my MultiSelect SFC component like so:
<script lang="ts">
export class Item {
static defaultHeight = 32;
key: number | string;
label: string;
height: number;
disabled: boolean | undefined;
constructor(
key: number | string,
label: string,
height?: number,
disabled?: boolean
) {
this.key = key;
this.label = label;
this.height = height ?? Item.defaultHeight;
this.disabled = disabled;
}
}
</script>
Then I just normally reference said type when mocking data for the component test.
This leads to ReferenceError: Item is not defined
when running the test.
Issue Analytics
- State:
- Created a year ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
vue.js - Uncaught ReferenceError: Component is not defined
In Navbar.vue I did not put quotes around the name being exported export default { name: 'Navbar', data(){ return{} }.
Read more >vite referenceerror: require is not defined - You.com
When importing a react component that imports a CSS file, vite fails with the message: Uncaught ReferenceError: require is not defined. If you...
Read more >Error Messages | Cypress Documentation
We found an error preparing your test file. This message means that Cypress encountered an error when compiling and/or bundling your test file....
Read more >ReferenceError is not defined errors in production but works in ...
I am quite new to vue.js, so I decided to start with the newest and greatest - Vue3, vite, script setup, etc. I...
Read more >3 Anti-Patterns to avoid in Vue.js - Binarcode
So let's dive in and see what are some common mistakes that should be avoided when developing with Vue.js. Side effects inside computed...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @StepanMynarik, good choice:) could you provide the test and the full component?
Thanks for having patience with me.
I just like to keep my SFCs tight. I even use the custom <i18n> block for localization. I can just grab any component and copy it into a separate repro/demo/any other project.
Also in combination with <style scoped> block, you will never have useless css nor localization tuples leftovers again.
I also enjoy not having to fish for any component related stuff. You only have the test tsx file right next to it, which is perfect.
Any tips on stripping the spec.tsx files from the final build?