Jest with coffeescript jsx?

前端 未结 3 1461
野趣味
野趣味 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 19:08

    I have just published a boiler plate unit test for Jest that works with React & CoffeeScript.

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

    The preprocessor needs to be as follows:

    var coffee = require('coffee-script');
    var ReactTools = require('react-tools');
    
    module.exports = {
      process: function(src, path) {
        // console.log('src', src);
        if (path.match(/\.coffee$/)) {
    
            // First we compile the coffeescript files to JSX
            compiled_to_js = coffee.compile(src, {bare: true});
    
            // Then we compile the JSX to React
            compiled_to_react = ReactTools.transform(compiled_to_js)
    
          return compiled_to_react;
        }
        return src;
      }
    };
    

提交回复
热议问题