Skip to content

Commit

Permalink
added source maps to karma, fixed 2 failing tests (were assuming the …
Browse files Browse the repository at this point in the history
…body was empty
  • Loading branch information
Nuno Campos committed Sep 13, 2016
1 parent f81b971 commit 9aa3b06
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
17 changes: 15 additions & 2 deletions karma.conf.js
Expand Up @@ -2,26 +2,35 @@ var webpack = require('webpack'); // eslint-disable-line no-var

module.exports = function karma(config) {
config.set({
basePath: '.',

plugins: [
'karma-chrome-launcher',
'karma-mocha',
'karma-webpack',
'karma-sourcemap-loader',
],
basePath: '.',

frameworks: ['mocha'],

files: [
'test/*.js',
],

exclude: [
'test/_*.js',
],

browsers: [
'Chrome',
],

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

webpack: {
devtool: 'inline-source-map',
resolve: {
extensions: ['', '.js', '.jsx', '.json'],
alias: {
Expand Down Expand Up @@ -49,5 +58,9 @@ module.exports = function karma(config) {
new webpack.IgnorePlugin(/react\/lib\/ExecutionEnvironment/),
],
},

webpackServer: {
noInfo: true,
},
});
};
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -84,6 +84,7 @@
"karma": "^0.13.22",
"karma-chrome-launcher": "^1.0.1",
"karma-mocha": "^1.0.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
"mocha": "^3.0.2",
"rimraf": "^2.5.4",
Expand Down
22 changes: 13 additions & 9 deletions test/ReactWrapper-spec.jsx
Expand Up @@ -2464,25 +2464,27 @@ describeWithDOM('mount', () => {
}
}
const div = global.document.createElement('div');

const initialBodyChildren = document.body.childNodes.length;
global.document.body.appendChild(div);

expect(document.body.childNodes).to.have.length(1);
expect(document.body.childNodes).to.have.length(initialBodyChildren + 1);
expect(div.childNodes).to.have.length(0);

const wrapper = mount(<Foo />, { attachTo: div });

expect(wrapper.find('.in-foo')).to.have.length(1);
expect(document.body.childNodes).to.have.length(1);
expect(document.body.childNodes).to.have.length(initialBodyChildren + 1);
expect(div.childNodes).to.have.length(1);

wrapper.detach();

expect(document.body.childNodes).to.have.length(1);
expect(document.body.childNodes).to.have.length(initialBodyChildren + 1);
expect(div.childNodes).to.have.length(0);

global.document.body.removeChild(div);

expect(document.body.childNodes).to.have.length(0);
expect(document.body.childNodes).to.have.length(initialBodyChildren);
expect(div.childNodes).to.have.length(0);
});

Expand All @@ -2499,33 +2501,35 @@ describeWithDOM('mount', () => {
}
let wrapper;
const div = global.document.createElement('div');

const initialBodyChildren = document.body.childNodes.length;
global.document.body.appendChild(div);

expect(document.body.childNodes).to.have.length(1);
expect(document.body.childNodes).to.have.length(initialBodyChildren + 1);
expect(div.childNodes).to.have.length(0);

wrapper = mount(<Foo />, { attachTo: div });

expect(wrapper.find('.in-foo')).to.have.length(1);
expect(document.body.childNodes).to.have.length(1);
expect(document.body.childNodes).to.have.length(initialBodyChildren + 1);
expect(div.childNodes).to.have.length(1);

wrapper.detach();

wrapper = mount(<Bar />, { attachTo: div });

expect(wrapper.find('.in-bar')).to.have.length(1);
expect(document.body.childNodes).to.have.length(1);
expect(document.body.childNodes).to.have.length(initialBodyChildren + 1);
expect(div.childNodes).to.have.length(1);

wrapper.detach();

expect(document.body.childNodes).to.have.length(1);
expect(document.body.childNodes).to.have.length(initialBodyChildren + 1);
expect(div.childNodes).to.have.length(0);

global.document.body.removeChild(div);

expect(document.body.childNodes).to.have.length(0);
expect(document.body.childNodes).to.have.length(initialBodyChildren);
expect(div.childNodes).to.have.length(0);
});

Expand Down

0 comments on commit 9aa3b06

Please sign in to comment.