Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support for DefineComponent shim #224

Merged
merged 4 commits into from
Oct 18, 2020
Merged

fix: support for DefineComponent shim #224

merged 4 commits into from
Oct 18, 2020

Conversation

pikax
Copy link
Member

@pikax pikax commented Oct 17, 2020

Support for the DefineComponent type

There's an issue with the passing the data function:

// TODO it should work
 mount(ShimedComponent, {
   data() {
     return {
       a: 1
     }
   }
})

@cexbrayat
Copy link
Member

@pikax I gave it a try in one of my projects and it's a bit better indeed (no more issue on mount 👍).

But I still have issues with the type of vm.

For example, if your component looks like:

export default defineComponent({
  name: 'HelloWorld',
  props: {
    msg: String,
  },
  setup() {
    return { user: reactive({ name: 'Cédric' }) };
  }
});

then mounting this component in a test succeeds, but vm does not expose user:

describe('HelloWorld.vue', () => {
  it('renders props.msg when passed', () => {
    const msg = 'new message'
    const wrapper = shallowMount(HelloWorld, {
      props: { msg }
    })
    expect(wrapper.text()).toMatch(msg)
    expect(wrapper.vm.user.name).toBe('Cédric');
  })
})

This last line does not compile with Vue 3.0.1 and this patch of VTU:

tests/unit/example.spec.ts:11:28 - error TS2339: Property 'name' does not exist on type 'never'.
    11     expect(wrapper.vm.user.name).toBe('Cédric');

But it does compile with Vue v3.0.0. So maybe this is something to fix in vue-next... WDYT?

@pikax
Copy link
Member Author

pikax commented Oct 17, 2020

Can you provide a full example?

It works on my side
image

@lmiller1990
Copy link
Member

lmiller1990 commented Oct 18, 2020

Good to merge this? Seems this should go out asap - or do we want to wait on @cexbrayat to confirm his issue with data?

Thanks guys, you rock 👍

@cexbrayat
Copy link
Member

@pikax this is exactly this use case, but using a SFC

See cexbrayat/vue-301-shims@819bab0
Even with your fix, there is still an issue with wrapper.vm

@lmiller1990 lmiller1990 merged commit 02cd7c9 into vuejs:master Oct 18, 2020
@pikax pikax deleted the fix/fix_issue_with_shim branch October 18, 2020 09:44
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.

None yet

3 participants