bluewings/pug-as-jsx-loader

Default "renders without crashing" test fails

Closed this issue · 2 comments

I have projects that runs without problem that uses pug-as-jsx-loader.

However when running npm test, no matter I am using cra-rewired or manually ejecting and modifying webpack config, I cannot get the default npm test passes.

TypeError: (0 , _App2.default) is not a function

       6 | class App extends Component {
       7 |   render() {
    >  8 |     return template({
         |            ^
       9 |       // variables
      10 |       logo,
      11 |     });

      at App.render (src/App.js:8:12)
      at finishClassComponent (node_modules/react-dom/cjs/react-dom.development.js:14301:31)
      at updateClassComponent (node_modules/react-dom/cjs/react-dom.development.js:14264:10)

Do we have suggested ways to do testing if we use pug-as-jsx-loader?

P.S. For the cra-rewired version, I tried cra-rewired -s react-scripts -m test -c webpack.custom.js but that seems to be an entrance to a a deeper hole.

@sunnypp
The jest transform module is required to solve this problem, but it does not currently exist.
Currently this loader is used exclusively for webpack, but should be used elsewhere, such as jest, rollup, etc.
To do this, I have to separate the code that converts the pug to jsx and make it available for use in various loaders. I've started this job from the repository below.
https://github.com/bluewings/pug-as-jsx-utils

I will inform you again in the future when the conversion module for the jest is complete.

@sunnypp
I am sorry for being late.
After npm install jest-transform-pug-as-jsx, add the pug transform setting in jest config.

see: 79c2c4f

Then you can pass npm test.

 PASS  src/App.test.js
  ✓ renders without crashing (22ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.462s
Ran all test suites.

Watch Usage: Press w to show more.

PS. I also updated the example for 'cra-rewired'.
https://github.com/bluewings/cra-rewired/tree/master/examples/pug-as-jsx-loader
You can override the jest setting as shown below.
https://github.com/bluewings/cra-rewired/blob/master/examples/pug-as-jsx-loader/config/jest.custom.js