Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Fix react(h) function #4

Merged
merged 5 commits into from
Aug 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function addAttribute(props, name, value, ctx) {
* `selector`. */
function react(h) {
var node = h && h('div');
return Boolean(node && node._store && node.key === null);
return Boolean(node && node._owner === null && node.key === null);
}

/* Check if `h` is `hyperscript`. It doesn’t accept
Expand Down
42 changes: 41 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,46 @@ test('hast-to-hyperscript', function (t) {
st.end();
});

t.test('should support `React.createElement`', function (st) {
t.test('should support `React.createElement` in `development`', function (st) {
var currentEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'development';

var baseline = doc.replace(/ camel-case="on off"/, '');
var actual = toH(r, hast);
var expected = r(
'h1',
{
key: 'h-1',
id: 'a',
className: 'b c',
hidden: true,
height: '2'
},
'bravo ',
r('strong', {
key: 'h-2',
style: {color: 'red'},
'aria-valuenow': '1',
'data-some': 'yes'
}, ['charlie']),
' delta',
r('input', {
key: 'h-3',
type: 'file',
accept: '.jpg, .jpeg'
})
);

st.deepEqual(html(rToString(actual)), html(baseline), 'equal output');
st.deepEqual(html(rToString(expected)), html(baseline), 'equal output baseline');
process.env.NODE_ENV = currentEnv;
st.end();
});

t.test('should support `React.createElement` in `production`', function (st) {
var currentEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'production';

var baseline = doc.replace(/ camel-case="on off"/, '');
var actual = toH(r, hast);
var expected = r(
Expand Down Expand Up @@ -170,6 +209,7 @@ test('hast-to-hyperscript', function (t) {

st.deepEqual(html(rToString(actual)), html(baseline), 'equal output');
st.deepEqual(html(rToString(expected)), html(baseline), 'equal output baseline');
process.env.NODE_ENV = currentEnv;
st.end();
});

Expand Down