How to set up Jest for CSS modules in Gatsby 3?

Viewed 79

In Gatsby 3 import styles from './styles.module.css' syntax is no longer supported and has been replaced with import * as styles from './styles.module.css'.

Unfortunately, using the new syntax doesn't work with the suggested Jest setup, i.e. using identity-obj-proxy for CSS modules - accessing any property on styles object returns undefined rather than the property name.

It does work correctly when I'm using named imports, e.g. import { wrapper } from './styles.module.css', but as I'm migrating a rather large app to Gatsby 3, I'd prefer to initially use import * as styles ... syntax.

Is there any other recommended way to set up Jest that would work with both import * as styles from ... and import { wrapper} from ...?

0 Answers
Related