Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda