Skip to content

Commit

Permalink
Bring back chai-enzyme.
Browse files Browse the repository at this point in the history
* Add `test-bundler.js`, which sets up chai/chai-enzyme, and requires all tests.

* Karma config: Only reference `test-bundler.js` instead of a glob.

* Webpack test config: Removed cheerio from externals
enzymejs/enzyme#47 (comment)
  • Loading branch information
MauriceWells committed Feb 7, 2016
1 parent 8653ac5 commit 20670df
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/components/Img/Img.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Img from './index';

import expect from 'expect';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import React from 'react';

describe('<Img />', () => {
it('should render an <img> tag', () => {
const renderedComponent = shallow(<Img src="test.png" alt="test" />);
expect(renderedComponent.find('img').length).toEqual(1);
expect(renderedComponent).to.have.tagName('img');
});

it('should have an alt attribute', () => {
const renderedComponent = shallow(<Img src="test.png" alt="test" />);
expect(renderedComponent.prop('alt')).toEqual('test');
expect(renderedComponent).to.have.attr('alt', 'test');
});
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
"babel-preset-react": "^6.3.13",
"babel-preset-react-hmre": "^1.0.1",
"babel-preset-stage-0": "6.3.13",
"chai": "^3.5.0",
"chai-enzyme": "^0.3.0",
"chalk": "^1.1.1",
"cheerio": "^0.19.0",
"css-loader": "^0.23.1",
"css-modules-require-hook": "^2.1.0",
"cssnano": "^3.4.0",
"enzyme": "^1.4.0",
"enzyme": "^1.5.0",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^3.1.0",
"eslint-plugin-react": "^3.15.0",
Expand Down
9 changes: 7 additions & 2 deletions webpack/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ module.exports = (config) => {
singleRun: true,

files: [
'../app/**/*.test.js'
{
pattern: `./test-bundler.js`,
watched: false,
served: true,
included: true
}
],

preprocessors: {
['../app/**/*.test.js']: ['webpack', 'sourcemap'],
['./test-bundler.js']: ['webpack', 'sourcemap']
},

webpack: webpackConfig,
Expand Down
13 changes: 13 additions & 0 deletions webpack/test-bundler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sinon from 'sinon';
import chai from 'chai';
import chaiEnzyme from 'chai-enzyme';

chai.use(chaiEnzyme());

global.chai = chai;
global.sinon = sinon;
global.expect = chai.expect;
global.should = chai.should();

const testsContext = require.context('../app', true, /\.test\.js$/);
testsContext.keys().forEach(testsContext);
1 change: 0 additions & 1 deletion webpack/webpack.test.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module.exports = {
// required for enzyme to work properly
externals: {
jsdom: 'window',
cheerio: 'window',
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': 'window'
},
Expand Down

0 comments on commit 20670df

Please sign in to comment.