# -*- coding: utf-8 -*-
import dukpy
class TestReactJS(object):
def test_hello_world(self):
jsx = dukpy.jsx_compile('var react_hello =
Hello, world!
;')
jsi = dukpy.JSInterpreter()
result = jsi.evaljs([
'''
var React = require('react/react'),
ReactDOM = require('react/react-dom-server');
''',
jsx,
'ReactDOM.renderToStaticMarkup(react_hello, null);'
])
assert result == 'Hello, world!
', res
def test_jsx_mixed(self):
code = '''
var React = require('react/react'),
ReactDOM = require('react/react-dom-server');
ReactDOM.renderToStaticMarkup(Hello, world!
, null);
'''
jsx = dukpy.jsx_compile(code)
res = dukpy.evaljs(jsx)
assert res == 'Hello, world!
', res
def test_react_binding(self):
code = '''
var React = require('react/react'),
ReactDOM = require('react/react-dom-server');
var HelloWorld = React.createClass({
render: function() {
return (
Hello {this.props.data.name}
);
}
});
ReactDOM.renderToStaticMarkup(, null);
'''
jsx = dukpy.jsx_compile(code)
res = dukpy.evaljs(jsx, data={'id': 1, 'name': "Alessandro"})
assert res == 'Hello Alessandro
', res
def test_jsx6(self):
code = '''
import React from 'react/react';
var ReactDOM = require('react/react-dom-server');
class HelloWorld extends React.Component {
render() {
return (
Hello {this.props.data.name}
);
}
}
ReactDOM.renderToStaticMarkup(, null);
'''
jsx = dukpy.jsx_compile(code)
res = dukpy.evaljs(jsx, data={'id': 1, 'name': "Alessandro"})
assert res == 'Hello Alessandro
', res