2015年4月19日 星期日

React.js - using Jest and Babel to test ES6 code

本偏介紹一下如果你是用 ES6 的語法寫的 React.js 應用程式,如果利用 Jest 測試時要住意那些部份

原則上測試的過程不外乎 Jest 官網介紹的 >>here<<

如果你是用 ES6 語法進行開發的話,你需要注意的是利用 react-tools 作 transform 時需要指定你的 JS 語法是 ES6

設定方式就是透過 preprocessor.js 讓 react-tools 在 transform 的時候可以將 ES6 語法 enabled 起來

根據 react-tools 的官方介紹,如同上述的方式加入 harmony 並指定為 true 就可以了

此外我再額外介紹一種方式就是利用 babel 來進行 transform 的動作

babel 本身就可以對 ES6 的語法以及 JSX 的進行轉換,所以你也不用擔心 babel 不認得 React.js

透過 npm install babel --save-dev 安裝 babel 之後

修改你的 preprocessor.js,如下所示:


3 則留言:

  1. security cctv cameras Karachi, Pakistan

    CCTV KARACHI

    www.cctvkarachi.pk
    sales@cctvkarachi.pk

    CCTV KARACHI

    回覆刪除
  2. We used java in our application-based products. It at first took time for Java to be adopted by the embedded market coz of heavy processing & large memory resource requirements but to address these limitations & meet embedded systems’ needs, some organizations offered reduced libraries with preselected functionalities. We are security CCTV Camera in Karachi, surveillance and communication solutions provider to business and home consumers.

    Reasons for java using in embedded systems are class libraries we don’t have to spend time rewriting existing functionalities, its reliable code coz Java handles the problems for you. OOP revolutionary concept that makes developers’ life easier, High performance & small footprint and Writes application once, run it on any other hardware platform.

    回覆刪除
  3. We used java in our application-based products. It at first took time for Java to be adopted by the embedded market coz of heavy processing & large memory resource requirements but to address these limitations & meet embedded systems’ needs, some organizations offered reduced libraries with preselected functionalities. We are security CCTV Camera in Karachi, surveillance and communication solutions provider to business and home consumers.

    Reasons for java using in embedded systems are class libraries we don’t have to spend time rewriting existing functionalities, its reliable code coz Java handles the problems for you. OOP revolutionary concept that makes developers’ life easier, High performance & small footprint and Writes application once, run it on any other hardware platform.

    回覆刪除