enzyme javascript

前回に次いで、enzymeで書いたらどうなるか。

.
├── .babelrc
├── package.json
├── src
│   └── CheckboxWithLabel.js
└── test
    ├── CheckboxWithLabel-test.js
    └── mocha.opts
(Φ ω Φ > cat .babelrc
{
  presets: ["airbnb"]
}
(Φ ω Φ > cat package.json
{
  "name": "enzyme-sample",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha test"
  },
  "dependencies": {
    "react": "^15.0.0",
    "react-dom": "^15.0.0"
  },
  "devDependencies": {
    "babel": "^6.3.26",
    "babel-preset-airbnb": "^1.0.1",
    "babel-register": "^6.4.3",
    "chai": "^3.5.0",
    "enzyme": "^2.0.0",
    "jsdom": "^8.0.1",
    "mocha": "^2.4.5",
    "react-addons-test-utils": "^15.0.0"
  },
  "author": "",
  "license": "ISC"
}
(Φ ω Φ > cat test/mocha.opts
--compilers js:babel-register
(Φ ω Φ > cat test/CheckboxWithLabel-test.js
import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import CheckboxWithLabel from '../src/CheckboxWithLabel.js';

describe('CheckboxWithLabel', () => {
  it('changes the text after click', () => {
    const checkbox = shallow(
      <CheckboxWithLabel labelOn="On" labelOff="Off" />
    );
    expect(checkbox.text()).to.equal('Off');

    checkbox.find('input').simulate('change');
    expect(checkbox.text()).to.equal('On');
  });
});

srcは一緒。