From 3518ecbbacab08635e3687685ba8fd8b69662e71 Mon Sep 17 00:00:00 2001 From: Michael Ridgway Date: Tue, 10 Mar 2015 20:24:50 -0700 Subject: [PATCH] Upgrade to include react@0.13; Fix tests that used deprecated features --- .travis.yml | 1 + lib/NavLink.js | 13 ++++--------- package.json | 6 +++--- tests/mocks/MockAppComponent.js | 24 ++++++++++++++++++++++++ tests/unit/lib/NavLink-test.js | 15 ++++++++------- 5 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 tests/mocks/MockAppComponent.js diff --git a/.travis.yml b/.travis.yml index 9b00205..9f31b13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: node_js matrix: allow_failures: diff --git a/lib/NavLink.js b/lib/NavLink.js index 31bcfe9..9fbf0b1 100644 --- a/lib/NavLink.js +++ b/lib/NavLink.js @@ -87,22 +87,17 @@ NavLink = React.createClass({ } }, render: function() { - var context; - if (this.context && this.context.makePath) { - context = this.context; - } else if (this.props.context && this.props.context.makePath) { - context = this.props.context; - } - + var context = this.props.context || this.context; var routeName = this.props.routeName; + var newProps = {}; if (!this.props.href && routeName && context) { - this.props.href = context.makePath(routeName, this.props.navParams); + newProps.href = context.makePath(routeName, this.props.navParams); } return React.createElement( 'a', objectAssign({}, { onClick: this.dispatchNavAction - }, this.props), + }, this.props, newProps), this.props.children ); } diff --git a/package.json b/package.json index 77c4955..2f3b4bd 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "setimmediate": "^1.0.2" }, "peerDependencies": { - "react": ">=0.12.0 <=0.13.0-rcx" + "react": ">=0.12.0 <=0.13.x" }, "devDependencies": { "chai": "^2.0.0", @@ -37,8 +37,8 @@ "lodash": "^3.2.0", "mocha": "^2.0.1", "precommit-hook": "^1.0.2", - "react": ">=0.12.0 <=0.13.0-rcx", - "react-tools": ">=0.12.0 <=0.13.0-rcx" + "react": ">=0.12.0 <=0.13.x", + "react-tools": ">=0.12.0 <=0.13.x" }, "jshintConfig": { "node": true diff --git a/tests/mocks/MockAppComponent.js b/tests/mocks/MockAppComponent.js new file mode 100644 index 0000000..c49cd37 --- /dev/null +++ b/tests/mocks/MockAppComponent.js @@ -0,0 +1,24 @@ +var React = require('react/addons'); +var RouterMixin = require('../../').RouterMixin; + +var MockAppComponent = React.createClass({ + + mixins: [RouterMixin], + + childContextTypes: { + executeAction: React.PropTypes.func, + getStore: React.PropTypes.func + }, + getChildContext: function () { + return { + executeAction: this.props.context.executeAction, + getStore: this.props.context.getStore + }; + }, + + render: function () { + return React.addons.cloneWithProps(this.props.children, {}); + } +}); + +module.exports = MockAppComponent; diff --git a/tests/unit/lib/NavLink-test.js b/tests/unit/lib/NavLink-test.js index 2801867..b7ddd6f 100644 --- a/tests/unit/lib/NavLink-test.js +++ b/tests/unit/lib/NavLink-test.js @@ -48,6 +48,7 @@ describe('NavLink', function () { React = require('react/addons'); ReactTestUtils = React.addons.TestUtils; NavLink = React.createFactory(require('../../../lib/NavLink')); + Wrapper = React.createFactory(require('../../mocks/MockAppComponent')); testResult = {}; }); @@ -69,16 +70,16 @@ describe('NavLink', function () { }); it ('only routeName defined', function () { var navParams = {a: 1, b: 2}; - var link = ReactTestUtils.renderIntoDocument(NavLink( {routeName:"foo", navParams:navParams, context:contextMock}, React.DOM.span(null, "bar"))); - expect(link.props.href).to.equal('/foo/a/1/b/2'); + var link = React.renderToString(NavLink( {routeName:"foo", navParams:navParams, context:contextMock}, React.DOM.span(null, "bar"))); + expect(link).to.contain('href="/foo/a/1/b/2"'); }); it ('only routeName defined; use this.context.makePath', function (done) { var navParams = {a: 1, b: 2}; - React.withContext(contextMock, function () { - var link = React.renderToString(NavLink({routeName:"foo", navParams:navParams})); - expect(link).to.contain('href="/foo/a/1/b/2"'); - done(); - }); + var link = React.renderToString(Wrapper({ + context: contextMock + }, NavLink({routeName:"foo", navParams:navParams}))); + expect(link).to.contain('href="/foo/a/1/b/2"'); + done(); }); it ('none defined', function () { var navParams = {a: 1, b: 2};