Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
Testing components with Jest using css modules

I'm working on a project in React using CSS modules for stylings.

I would like to test a component using Jest and React Testing Library, but when I try to render it I get this error:

Test suite failed to run

cssModule has no keys

  3 | export default (style: {[key: string]: string}):any => {
  4 |     block.setSettings({throwOnError: true, modifierDelimiter: '--'});
> 5 |     return block(style);
    |                 ^
  6 | };
  7 |

block is an override from a function exported by the library bem-css-modules which I use for keeping BEM nomenclature while implementing css-modules.

I have managed to log the exact style (imported by the .module.scss file) which is passed to this function, and I have found that it is actually empty when rendering the component with react-testing-library:

import React from 'react';
import MyIcon from 'shared/components/myIcon/myIcon.component';
import styles from './myButton.module.scss';
import block from 'utils/bemCssModulesConfig';

console.log('styles', styles) // this logs "styles, {}" so it's empty object
const bem = block(styles);

This is the moduleNameMapper I am currently using:

"moduleNameMapper": {
      "^.+\\.(scss|sass|css|less)$": "identity-obj-proxy"
}

I have already tryed using custom proxies copied from the internet or using external libraries as moduleNameMappers.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!