Skip to content

Commit

Permalink
[test] Adding tests for this
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Feb 27, 2015
1 parent c3bd70d commit ca997fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions fixtures/this.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>{this.props.name}</div>
30 changes: 29 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('react-jsx', function () {

var Hello = React.createClass({
render: function render() {
return jsx.server(fixtures.hello, { render: 'DOM' })(this);
return jsx.server(fixtures.hello)(this);
}
});

Expand Down Expand Up @@ -61,6 +61,12 @@ describe('react-jsx', function () {
assume(client).is.a('function');
assume(React.isValidElement(client({ defaultValue: 1 }))).is.true();
});

it('can also output HTML', function () {
var client = jsx.client(fixtures.react, { raw: true });

assume(client({}, { html: true })).equals('<div>content</div>');
});
});

describe('.server', function () {
Expand Down Expand Up @@ -119,5 +125,27 @@ describe('react-jsx', function () {

assume(result).equals('<div>Hello john</div>');
});

it('assumes data should be used as this if it has props', function () {
var server = jsx.server('<Hello name="lol" />', { raw: true })
, that = jsx.server(fixtures.this);

var Hello = React.createClass({
render: function () {
return that(this);
}
});

assume(server).is.a('function');
assume(server({ Hello: Hello }, { html: true })).equals('<div>lol</div>');
});

it('works with a custom `this`', function () {
var that = jsx.server(fixtures.this, { raw: true });

assume(that.call({
props: { name: 'john' }
}, {}, { html: true })).equals('<div>john</div>');
});
});
});

0 comments on commit ca997fd

Please sign in to comment.