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

CSS v-bind includes absolute path, thus breaking tests running on different machines #2061

Open
alvaromat opened this issue Apr 4, 2023 · 2 comments

Comments

@alvaromat
Copy link

Subject of the issue

Using v-bind in css styles creates an html output that includes the absolute path:

Steps to reproduce

Component with a style binding:

<template>
  <div>
    hello
  </div>
</template>
<script setup>
const margin = ref('40px')
</script>
<style scoped>
div {
  margin: v-bind(margin);
}
</style>

Then using jest snapshots:

import { shallowMount } from '@vue/test-utils'
import Component from './Component.vue'

  it('renders correctly', () => {
    wrapper = shallowMount(Component)
    expect(wrapper.html()).toMatchSnapshot()
  })

The snapshot created:

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
"<div style="--/Users/alvaro/Documents/test-project/Component.vue-margin: 0;">
  hello
</div>"
`;

Expected behaviour

The snapshot shouldn't contain the absolute path, so it doesn't break between machines:

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
"<div style="--Component.vue-margin: 0;">
  hello
</div>"
`;

Actual behaviour

The snapshot contains an absolute path, so running the same test on a different path/machine will fail.

Possible Solution

Name the CSS variable differently.

@qnhat358
Copy link

@alvaromat Have you fixed it?

@ShGKme
Copy link

ShGKme commented Nov 20, 2023

This is not a part of @vue/test-utils. The error is caused on SFC transform for Jest by @vue/vue3-jest.
See:

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

No branches or pull requests

3 participants