ionic-framework: bug: vue jest utils, shallowMount does not work when property values are symbols

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

After bumping Ionic Vue from v5 to v6 RC, all my tests that are shallowMounted fail with the following error:

Screen Shot 2021-11-08 at 09 41 06

Expected Behavior

This didn’t happen with v5, and I expect it to work in v6 as well

Steps to Reproduce

Run an Ionic 6 app test with shallowMount

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 6.17.1

Utility:

cordova-res : not installed globally native-run : not installed globally

System:

NodeJS : v17.0.1 npm : 8.1.0 OS : macOS Monterey

Additional Information

Also see https://github.com/vuejs/vue-test-utils/issues/1833

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 29 (8 by maintainers)

Most upvoted comments

We actually found a way to fix this in Vue core if anyone is curious: https://github.com/vuejs/vue-next/pull/4964

@lmiller1990 great! By the way, there is also an open issue for this in VTU v1 that would be fixed by backporting this: https://github.com/vuejs/vue-test-utils/issues/1833

Edit, I just implemented it, much faster, please give me some 👀 https://github.com/vuejs/vue-test-utils-next/pull/1086

Be really good if someone could try this against their repos with problems and see if it works. Easiest way to test would be clone and checkout my branch, yarn build, and copy paste the dist directory in your your node_modules/@vue/test-utils/dist.

I don’t think we can stub out a JS primitive constructor. It would be like replacing String or Array.

I see this doesn’t work in a real browser either - if you open your console and do document.body.setAttribute('sym', Symbol()) you get a similar error. I think for this reason we probably do want to remove any symbols that would be passed as attributes to stubs… I’m not sure how difficult this is to do, I can give it a try.

If anyone else would like to work on this in the meantime, I think you need to write some code here. There’s a minimal reproduction here.

What you’d need to do is something like this on this line

const render = (ctx: ComponentPublicInstance) => {
  // take $ctx.props and filter out any keys that have a symbol
  // consider you can also have a `default` value which is a function that returns a symbol
  // const props = {} 
  // for (const [k, v] of Object.entries(ctx.$props)) {
  //   # if symbol, continue
  //   # else props[key] = v
  // }
  return h(tag, ctx.$props, renderStubDefaultSlot ? ctx.$slots : undefined)
}

Happy to work with someone if anyone would like to give this a try - I’m trying to grow the contributors to Test Utils to make it better for everyone 😃

Thanks Liam 😃 appreciated. Hope this gets fixed before Ionic 6 reaches stable!