Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelro committed May 29, 2017
1 parent 99a89db commit 869a2d9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions .nyc_output/5084cd7a70bb652877178f4d238e88ea.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions config/webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class Config{

if(!_.isEmpty(options)) plugin = pluginFunction.call(this, options);

if(!_.property(plugin, 'name'))
if(!_.isString(plugin.name))
throw new Error('invalid-prop', 'The generated plugin must contain a name property');

if(!_.property(plugin, 'plugin'))
if(!_.isObject(plugin.plugin))
throw new Error('invalid-prop', 'The generated plugin must contain a plugin property');

if(!this.config.plugins) this.config.plugins = [];
Expand Down
52 changes: 50 additions & 2 deletions config/webpack/tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,58 @@ describe( 'webpack', function() {

describe( 'method', function ( ) {

describe( 'preset', function () {
describe( 'setPreset', function () {
describe( 'when passed other value than "drupal"', function(){
it( 'should throw', function () {
assert.throws( () => config.setPreset('wordpress'), Error );
assert.throws( () => webpack.setPreset('wordpress'), Error );
} );
} );
} );

describe( 'addPlugin', function () {
var pluginParams = {
funcWithName(){
return {
name: 'test',
plugin: function(){}
}
},
funcWithoutName(){
return {
plugin: function(){}
}
},
funcWithoutPlugin(){
return {
name: 'test'
}
}
}

beforeEach(function(){
webpack.options.plugins.test = { test: 'option' }
sinon.spy(pluginParams, 'funcWithName');
});

afterEach(function(){
pluginParams.funcWithName.restore();
});

describe( 'when passed param is not a function', function(){
it( 'should throw', function () {
assert.throws( () => webpack.addPlugin(), Error );
} );
} );

describe( 'when returned plugin config does not have a name', function(){
it( 'should throw', function () {
assert.throws( () => webpack.addPlugin(pluginParams.funcWithoutName), Error );
} );
} );

describe( 'when returned plugin config does not have a plugin', function(){
it( 'should throw', function () {
assert.throws( () => webpack.addPlugin(pluginParams.funcWithoutPlugin), Error );
} );
} );
} );
Expand Down

0 comments on commit 869a2d9

Please sign in to comment.