From 92eadf27289f5790d650e972afe2d3756fd35c5d Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Wed, 16 Mar 2016 14:23:18 -0500 Subject: [PATCH] Add ability to use value prop and fall back to children Fixes #34 --- src/generator.js | 5 +++-- test/general.spec.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/generator.js b/src/generator.js index 4f8be39..44dffee 100644 --- a/src/generator.js +++ b/src/generator.js @@ -24,8 +24,9 @@ function generator(fn, argArray, options) { return componentProps[element]; }); - // Get value from this.props.children. - this.args[0] = this.props.children; + // Get value from this.props.value if set else from + // this.props.children. + this.args[0] = this.props.hasOwnProperty("value") ? this.props.value : this.props.children; if (this.props["locale"]) { this.instance = Globalize(this.props["locale"]); diff --git a/test/general.spec.js b/test/general.spec.js index c7ddb1f..5f0341f 100755 --- a/test/general.spec.js +++ b/test/general.spec.js @@ -6,4 +6,14 @@ describe("General Functionality Tests", () => { const wrapper = shallow({150}); expect(wrapper.text()).to.equal("150,00 €"); }); + + it("uses value prop instead of children to display $200.00", () => { + const wrapper = shallow({150}); + expect(wrapper.text()).to.equal("$200.00"); + }); + + it("uses value prop instead of children to display $0.00 even though 0 is falsey", () => { + const wrapper = shallow({150}); + expect(wrapper.text()).to.equal("$0.00"); + }); });