Jest with coffeescript jsx?

前端 未结 3 1457
野趣味
野趣味 2021-01-11 18:27

How can I use Jest to test React components written in CoffeeScript + React jsx?

The only CoffeeScript example provided with Jest uses plain CoffeeScript, and doesn\

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-11 18:48

    Based on user2534631's template project, I enhanced to use coffee-react-transform to compile CJSX files.

    https://github.com/redice/jest-react-coffeescript

    var coffee = require('coffee-script');
    var transform = require('coffee-react-transform');
    
    module.exports = {
      process: function(src, path) {
        if (coffee.helpers.isCoffee(path)) {
          compiled_cjx = transform(src);
          compiled_to_react = coffee.compile(compiled_cjx, {bare: true});
    
          return compiled_to_react;
        }
    
        return src;
      }
    };
    

    So use CJSX syntax to write React components.

    render: ->
      
    

提交回复
热议问题