Skip to content

Commit

Permalink
Update test with use or rewire around basicsActions and validate that…
Browse files Browse the repository at this point in the history
… it runs
  • Loading branch information
GordyD committed Dec 16, 2015
1 parent bcf7841 commit bd4d7ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions test.config.js
@@ -1,5 +1,6 @@
var path = require('path');
var webpack = require('webpack');
var RewirePlugin = require("rewire-webpack");

var definePlugin = new webpack.DefinePlugin({
__DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'false')),
Expand Down Expand Up @@ -27,6 +28,7 @@ module.exports = {
},
plugins: [
definePlugin,
new RewirePlugin(),
new webpack.DefinePlugin({
'process.env': Object.keys(process.env).reduce(function(o, k) {
o[k] = JSON.stringify(process.env[k]);
Expand Down
19 changes: 15 additions & 4 deletions test/blip/basics/DailyDose.test.js
Expand Up @@ -4,10 +4,21 @@
var React = require('react');
var TestUtils = require('react-addons-test-utils');
var expect = chai.expect;
var rewire = require('rewire');

var DailyDose = require('../../../plugins/blip/basics/components/chart/DailyDose');
var DailyDose = rewire('../../../plugins/blip/basics/components/chart/DailyDose');

describe('DailyDose', function () {
var basicsActions = {
addToBasicsData: sinon.stub()
};

DailyDose.__set__('basicsActions', basicsActions);

beforeEach(function() {
// Reset the stub before each test
basicsActions.addToBasicsData = sinon.stub()
});

it('should be a function', function() {
expect(DailyDose).to.be.a('function');
Expand Down Expand Up @@ -245,7 +256,7 @@ describe('DailyDose', function () {
React.findDOMNode(inputElem).value = 2.3;

elem.onClickCalculate();
expect(props.addToBasicsData.withArgs('weight', 2.3).callCount).to.equal(1);
expect(basicsActions.addToBasicsData.withArgs('weight', 2.3).callCount).to.equal(1);
});

it('should not result in call to addToBasicsData when weight is 0', function() {
Expand All @@ -263,7 +274,7 @@ describe('DailyDose', function () {
React.findDOMNode(inputElem).value = 0;

elem.onClickCalculate();
expect(props.addToBasicsData.callCount).to.equal(0);
expect(basicsActions.addToBasicsData.callCount).to.equal(0);
});

it('should not result in call to addToBasicsData when weight is not a number', function() {
Expand All @@ -281,7 +292,7 @@ describe('DailyDose', function () {
React.findDOMNode(inputElem).value = 'foo';

elem.onClickCalculate();
expect(props.addToBasicsData.callCount).to.equal(0);
expect(basicsActions.addToBasicsData.callCount).to.equal(0);
});
});
});

0 comments on commit bd4d7ee

Please sign in to comment.