added html tests

This commit is contained in:
avim 2014-11-11 13:06:11 +02:00
parent c5d8fdd888
commit 1ed5eb873e
3 changed files with 40 additions and 0 deletions

9
test/data/scope.rt Normal file
View File

@ -0,0 +1,9 @@
<!DOCTYPE jsx>
<div>
<div rt-scope="['a','b','c'] as items">
<span rt-repeat="item in items">Item:#{itemIndex} = {item}</span>
</div>
<span>{typeof (items) == 'undefined'?'items not in scope':'items in scope'}</span>
<span>{typeof (item) == 'undefined'?'item not in scope':'item in scope'}</span>
</div>

1
test/data/scope.rt.html Normal file
View File

@ -0,0 +1 @@
<div><div><span>Item:#0 = a</span><span>Item:#1 = b</span><span>Item:#2 = c</span></div><span>items not in scope</span><span>item not in scope</span></div>

View File

@ -4,6 +4,7 @@ var reactTemplates = require('../../src/reactTemplates');
var fs = require('fs');
var _ = require('lodash');
var path = require('path');
var React = require('react');
var dataPath = path.resolve(__dirname, '..', 'data');
@ -26,3 +27,32 @@ test('conversion test', function (t) {
}
});
test('html tests', function (t) {
var files = ['scope.rt'];
t.plan(files.length);
files.forEach(check);
function check(testFile) {
var filename = path.join(dataPath, testFile);
var html = fs.readFileSync(filename).toString();
var expected = fs.readFileSync(filename + '.html').toString().replace(/\r/g,"");
// var expected = fs.readFileSync(filename.replace(".html", ".js")).toString();
var code = reactTemplates.convertTemplateToReact(html).replace(/\r/g,"");
var define = function (req,content) {
return content(React, _);
};
console.log(code);
var comp = React.createFactory(React.createClass({
render: eval(code)
}));
var actual = React.renderToStaticMarkup(comp());
console.log(actual);
t.equal(actual, expected);
if (actual !== expected) {
fs.writeFileSync(filename + '.actual.js', actual);
}
}
});