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.
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);
});
});
});
As Mocha's official docs discourage the use of arrow functions in tests, we should rewrite the test template to use inline functions.
The change would affect
Examples
test/.eslintrc
Some V4 test