question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Vue 3 Component Test Error: "ReferenceError: Item is not defined"

See original GitHub issue

Context:

  • 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:open
  • Created a year ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
sand4rtcommented, Oct 26, 2022

Hi @StepanMynarik, good choice:) could you provide the test and the full component?

1reaction
StepanMynarikcommented, Oct 27, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found