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.

Typescript error on render with a defineComponent (v6.0)

See original GitHub issue

Describe the bug A clear and concise description of what the bug is.

Try to call render() on a component define with defineComponent({...}). This error is reported by typescript :

Argument of type 'DefineComponent<{}, {}, any, Record<string, ComputedGetter<any> | WritableComputedOptions<any>>, MethodOptions, ... 6 more ..., {}>' is not assignable to parameter of type 'VueClass<any>'.
  Type 'ComponentPublicInstanceConstructor<any, any, any, any, Record<string, ComputedGetter<any> | WritableComputedOptions<any>>, MethodOptions> & ComponentOptionsBase<...> & VNodeProps & AllowedComponentProps & ComponentCustomProps' is missing the following properties from type 'VueConstructor<Vue>': extend, nextTick, set, delete, and 9 more.ts(2345)

To Reproduce Steps to reproduce the behavior:

  • Create a project from the vue-cli ( typescript + unit test with jest)
  • convert the generate test to :
const msg = 'new message'
    render(HelloWorld, {
      props: { msg },
    })
    const elt = await screen.findByText(msg)
    expect(elt).toBeDefined()

Expected behavior

No TS error

Screenshots

Related information:

  • @testing-library/vue version: 6.0.0
  • Vue version: 3.0

Relevant code or config (if any)

To throw away the error I did a shim for vue-testing–library in my project. I am not a TS expect so i do not kwnow if it is a correct shim

// src/shims-vue-testing-library.d.ts
import { ConfigurationCallback, RenderOptions } from '@testing-library/vue'
import Vue, { DefineComponent } from 'vue'

declare module '@testing-library/vue' {
  export function render<V extends Vue>(
    TestComponent: DefineComponent<{}, {}, any> | VueClass<V>,
    options?: RenderOptions<V>,
    configure?: ConfigurationCallback<V>,
  ): ComponentHarness
}

Thank you for this great wrapper.

I read some issues that worry me about the routing. Can I easily use a real router with vue-testing-library ? Sadly VTU seems to focus on the mock path 😕

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
uncleramsaycommented, Sep 1, 2022

Is it possible to get this fix backpatched to version 5? I’m not able to upgrade to Vue 3 yet, but am using defineComponent with Vue2.7 and running into this same issue. Thanks!

2reactions
afontcucommented, Nov 3, 2020

It is great, though, that our findByXXX helps us overcome a lot of limitations when it comes to async navigation 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting error in unit test from new vue 3 project generated by CLI
Even though I've used Javascript for a long time I am new to typescript and unable to read the error properly/make sense of...
Read more >
Getting Started with React Navigation v6 and TypeScript in ...
In this tutorial, let's look at how you can set up and use React Navigation and TypeScript together in a React Native app....
Read more >
Ionic Vue Quickstart
Our QuickStart guide covers the basics of both Vue and Ionic Framework global components to get apps up and running. Read how to...
Read more >
testing-library - Bountysource
Try to call render() on a component define with defineComponent({...}) . This error is reported by typescript : Argument of type 'DefineComponent<{}, ...
Read more >
'defineComponent' in Vue 3 Is Pure Magic! - Telerik
But, there's still that one nasty TypeScript error that doesn't want to go away, and it's breaking the build no matter what you...
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