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

Bug: Providing global.config.compilerOptions.whitespace doesn’t work consistently #1502

Closed
ghost opened this issue May 17, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented May 17, 2022

Describe the bug

During the upgrade process of a project to Vue 3 & Vue Test Utils 2, I’ve noticed a failing test that’s caused by a different whitespace setting used during test execution than what’s otherwise used in the project (via compiler options set in the project’s webpack configuration).

After trying to provide a minimal reproduction, it looks like setting global.config.compilerOptions.whitespace via a mount call’s options doesn’t always work. Specifically, setting it once (to any value) seems to prevent it being set to a different value in subsequent mount calls.

To Reproduce

Run the following test code in a project with @vue/test-utils installed. Both tests should pass, but the second will fail. Note also how changing the order of the tests makes it so that the test will fail that’s now the second even though it previously passed.

const { mount } = require('@vue/test-utils')

const Component = {
  template: `
    <div>
      <h2>
        Heading
      </h2>
    </div>
  `
}

// Skipping this test allows the second test pass. Without skipping it, the second test fails.
test('works with whitespace “preserve”', () => {
  const wrapper = mount(Component, {
    global: {
      config: {
        compilerOptions: {
          whitespace: 'preserve',
        },
      },
    },
  })

  expect(wrapper.html()).toBe(`<div>
  <h2>
    Heading
  </h2>
</div>`)
})

test('works with whitespace “condense”', () => {
  const wrapper = mount(Component, {
    global: {
      config: {
        compilerOptions: {
          whitespace: 'condense',
        },
      },
    },
  })

  expect(wrapper.html()).toBe(`<div>
  <h2> Heading </h2>
</div>`)
})

Used Jest configuration:

module.exports = {
  testEnvironment: 'jsdom',
  transform: {
    '^.+\\.js$': 'babel-jest',
  },
}

Expected behavior

Related information:

  • @vue/test-utils version: 2.0.0-rc.21
  • Vue version: none
  • node version: v16.15.0
  • npm (or yarn) version: v8.10.0

Additional context

I’ve tried avoiding this issue by globally setting this in a Jest setup file, but that didn’t help.

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

config.global.config.compilerOptions = {
  whitespace: 'preserve',
}
@ghost ghost added the bug Something isn't working label May 17, 2022
@freakzlike
Copy link
Collaborator

I'm not sure, but I think this has been removed by #1408 ?

@cexbrayat
Copy link
Member

Yes, exactly. compilerOptions have no effect in the config of VTU.

You need to configure Jest as explained here https://github.com/vuejs/vue-jest#global-jest-options

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

No branches or pull requests

2 participants