question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sass support in jest test files appear to be broken

See original GitHub issue

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

(Write your answer here.)

Which terms did you search for in User Guide?

Sass support

(Write your answer here if relevant.)

Environment

  1. node -v:
  2. npm -v:
  3. yarn --version (if you use Yarn):
  4. npm ls react-scripts (if you haven’t ejected):

Then, specify:

  1. Operating system:
  2. Browser and version (if relevant):

Steps to Reproduce

(Write your steps here:)

1: Update react-scripts to latest release 2: Import styles from ‘component.module.scss’ in component file 3: Import styles from ‘component.module.scss’ in component.test.js

Expected Behavior

(Write what you thought would happen.)

Classnames are imported for component file and test file correctly for comparison

see #3815

Actual Behavior

(Write what happened. Please add screenshots!)

Component imports classNames correctly, test file classnames are undefined

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Tasemucommented, Apr 25, 2018

it also appears that importing css modules is not working as expected either.

import styles from './test.module.css';
import sass from './sass.module.scss';

it('should handle css modules', () => {
  console.log(styles) // => {}
})

it('should handle sass modules', () => {
  console.log(styles) // => 'sass.module.scss'
})

Using this configuration:

transformIgnorePatterns: [
      '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$',
      '^.+\\.module\\.{css,sass,scss}$',
    ],
    moduleNameMapper: {
      '^react-native$': 'react-native-web',
      '^.+\\.module\\.{css,sass,scss}$': 'identity-obj-proxy',
    },
1reaction
Tasemucommented, Apr 23, 2018

I’m going to attempt a PR too 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Syntax Error when test component with SASS file imported
My setup includes a jest.config.js file. I found that if I added "moduleNameMapper" there, it worked. So now my jest.test.config.js looks something like ......
Read more >
Testing Sass with Jest
How to test Sass compilation, enforcing good hygiene and testing Sass functions and mixins using Jest.
Read more >
How To Set Up Next.JS With Jest, React Testing Library and ...
Let's break it down: collectCoverageFrom : Tells Jest that we want to collect via a glob pattern (basically just saying we want to...
Read more >
jest-preview | Yarn - Package Manager
Preview your Jest tests in a browser ... Display full readme Display full readme ... Support viewing SVG when importing as a component...
Read more >
How to Import a Sass File into Every Vue Component in an App
If you have to redefine some base pieces of your application in every component, it will begin to break down, just like a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found