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

Config leaks between tests #1187

Closed
purepear opened this issue Dec 27, 2021 · 2 comments · Fixed by #1202
Closed

Config leaks between tests #1187

purepear opened this issue Dec 27, 2021 · 2 comments · Fixed by #1202
Labels
bug Something isn't working

Comments

@purepear
Copy link
Contributor

Thanks for the great work, guys! 🙇
I just noticed that when i pass the router plugin in a test, then the rest of the tests were inheriting the router.

mount(Component, { global: { plugins: [router] }})

I also have a global config setup:

config.global.config.globalProperties = {
  $router: routerMock,
  $route: routeMock,
}

I believe it has sth to do with the config merging strategy - it uses shallow clone and in the case of deeply nested objects, it overwrites the VTU's global config object. This might not be limited to plugins/config/globalProperties but other parts of the config as well 🤔

Here's how to reproduce:

import { config, mount } from '@vue/test-utils'
import { h } from 'vue'

config.global.config.globalProperties = {
  $anotherThing: 'not used but sth to demonstrate a non-empty global config',
}

const Plugin = {
  install(app) {
    app.config.globalProperties.$something = 'something'
  },
}

const Component = {
  render() {
    return h('div', this.$something)
  },
}

test('should pass with plugin', () => {
  const wrapper = mount(Component, {
    global: {
      plugins: [Plugin],
    },
  })

  expect(wrapper.html()).toContain('something')
})

test('should pass without plugin but it fails!', () => {
  const wrapper = mount(Component)

  expect(wrapper.html()).not.toContain('something')
})
@LinusBorg LinusBorg added the bug Something isn't working label Dec 27, 2021
@cexbrayat
Copy link
Member

Thanks @purepear for the repro 👍

Would you like to work on a PR to fix this? If you add this test to config.spec.ts, you may be able to figure out what's going on.

@purepear
Copy link
Contributor Author

@cexbrayat yep, i will see if i can raise a PR during the weekend. Haven't looked too deep into the code but i suspect cloneDeep will be involved in the fix :) I guess a potential problem of config cloning might be a config with class/component instances but... 🤔 will see

purepear added a commit to purepear/vue-test-utils-next that referenced this issue Jan 1, 2022
purepear added a commit to purepear/vue-test-utils-next that referenced this issue Jan 1, 2022
purepear added a commit to purepear/vue-test-utils-next that referenced this issue Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants