Vue-jest: Importing a CSS file in a component throws an error

Created on 20 Sep 2019  路  2Comments  路  Source: vuejs/vue-jest

I scaffolded out a @vue/cli project with Jest included. Then installed Bootstrap, and included the CSS file into the HelloWorld.vue component.

When running yarn unit:test, I get the following error:
image

Jest config (in package.json) includes:

".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$": "jest-transform-stub",

Repo: https://github.com/darthmeme/vue-jest-import-css

Most helpful comment

Jest doesn't apply transforms to node_modules by default. You can solve this by using moduleNameMapper in your jest config file:

{
  "jest": {
    // ..
    "moduleNameMapper": {
      "^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
    }
  }
}

From jest-transform-stub FAQ

All 2 comments

Jest doesn't apply transforms to node_modules by default. You can solve this by using moduleNameMapper in your jest config file:

{
  "jest": {
    // ..
    "moduleNameMapper": {
      "^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
    }
  }
}

From jest-transform-stub FAQ

@cp3r - hey, thanks for the reply! I recently found that out, but forgot about this issue. Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lancetharper picture lancetharper  路  6Comments

yohodopo picture yohodopo  路  4Comments

rmartins90 picture rmartins90  路  6Comments

nothingismagick picture nothingismagick  路  4Comments

ccamarat picture ccamarat  路  7Comments