react-webpack-generators / generator-react-webpack

Yeoman generator for ReactJS and Webpack
http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/
MIT License
2.88k stars 355 forks source link

Refactor arrow functions to function() in test template #275

Closed sthzg closed 8 years ago

sthzg commented 8 years ago

As Mocha's official docs discourage the use of arrow functions in tests, we should rewrite the test template to use inline functions.

Passing arrow functions (“lambdas”) to Mocha is discouraged. Due to the lexical binding of this, such functions are unable to access the Mocha context. For example, the following code will fail due to the nature of lambdas. [...] If you do not need to use Mocha’s context, lambdas should work. However, the result will be more difficult to refactor if the need eventually arises.

The change would affect

Examples

test/.eslintrc

{
  "env": {
    "mocha": true
  },
  "rules": {
    "prefer-arrow-callback": "off",
    "func-names": "off"
  },
  "globals": {
    "expect": true
  }
}

Some V4 test

import React from 'react';
import { shallow } from 'enzyme';
import App from 'components/App';

describe('<App />', function () {

  beforeEach(function () {
    this.component = shallow(<App />);
  });

  describe('when rendering the component', function () {

    it('should have a className of "index"', function () {
      expect(this.component.hasClass('index')).to.equal(true);
    });
  });
});
weblogixx commented 8 years ago

@sthzg: Interesting, I did not know that. I havent had any issues with this, either. However, I too think we should stick to the recommendations. 👍