Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
allow onClick handler to be overwritten for customization
Browse files Browse the repository at this point in the history
  • Loading branch information
lingyan committed Nov 5, 2014
1 parent 9dd634b commit a9a09c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/NavLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ NavLink = React.createClass({
if (!this.props.href && routeName && context && context.makePath) {
this.props.href = context.makePath(routeName, this.props.navParams);
}
console.log('....... this.props=', this.props);
return React.createElement(
'a',
objectAssign({}, this.props, {
onClick: this.dispatchNavAction,
href: this.props.href
}),
objectAssign({}, {
onClick: this.dispatchNavAction
}, this.props),
this.props.children
);
);
}
});

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/lib/NavLink-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ var React,
jsdom = require('jsdom'),
expect = require('chai').expect,
contextMock,
onClickMock,
routerMock,
testResult;

onClickMock = function () {
testResult.onClickMockInvoked = true;
};

routerMock = {
makePath: function (name, params) {
var paths = ['/' + name];
Expand Down Expand Up @@ -97,4 +102,16 @@ describe('NavLink', function () {
}, 10);
});
});

it('allow overriding onClick', function (done) {
var navParams = {a: 1, b: true},
link = ReactTestUtils.renderIntoDocument(NavLink( {href:"/foo", context:contextMock, navParams:navParams, onClick: onClickMock}, React.DOM.span(null, "bar")));
expect(testResult.onClickMockInvoked).to.equal(undefined);
ReactTestUtils.Simulate.click(link.getDOMNode());
window.setTimeout(function () {
expect(testResult.dispatch).to.equal(undefined);
expect(testResult.onClickMockInvoked).to.equal(true);
done();
}, 10);
});
});

0 comments on commit a9a09c0

Please sign in to comment.