Mojito markup test
Mojito markup test 能使用模拟数据来呈现 mojit 视图,得到的结果可以用来验证使用 YUI 节点模块。若是使用 mojito test
指令,则由它得到的实力能够在 mojito 单元测试中运行。
使用步骤:
需要
mojito-markup-test
.增加一个 mojit
spec
.-
呈现视图和验证标记.
YUI.add('CompositeMojit_view-tests', function(Y) { var suite = new YUITest.TestSuite('CompositeMojit'), A = YUITest.Assert, MarkupTest = Y.mojito.MarkupTest, //Timeout for async testing TIMEOUT = 1000; suite.add(new YUITest.TestCase({ name: 'view', 'test index': function () { var test = this, //describe the mojit to render spec = { //mojit type (dir name) type: 'CompositeMojit', //action to test action: 'index', //mojit params params: { url: { p: 'Really!' } }, //mojit config (to use with ac.config.get() ) config: { foo: 'bar' }, //app level config (to use with ac.app) appConfig: { some: 'config param' }, // We need to define the child mojits, // modules should be in the requires: [] as well to be loaded (see below) children: { 'child_mojit': { type: 'ChildMojit' } } }; MarkupTest.render(spec, function (err, markup, meta, node) { //rendering done, resume paused test and verify test.resume(function () { var div, em, i, a, text; A.isNull(err); //we have markup A.areNotEqual('', markup, 'Markup'); //we have meta A.isNotNull(meta, 'Meta'); //we have a node A.isNotUndefined(node, 'Parent node'); A.isNotNull(node, 'Parent node'); div = node.one('.msg'); A.isNotUndefined(div, 'msg <div>'); A.isNotNull(div, 'msg <div>'); em = div.one('em'); A.isNotUndefined(em, '<em>'); A.isNotNull(em, '<em>'); text = em.getContent(); A.areEqual('Mojito is working.', text, 'Rendered message <em>'); i = div.one('i'); A.isNotUndefined(i, '<i>'); A.isNotNull(i, '<i>'); text = i.getContent(); A.areEqual(spec.params.url.p, text, 'Rendered message <i>'); a = div.one('a'); A.isNotUndefined(a, '<a>'); A.isNotNull(a, '<a>'); text = a.getContent(); A.areEqual(spec.config.foo, text, 'Rendered message <a>'); }); }); //we need this for async tests, wait till rendering done or timeout test.wait(TIMEOUT); } })); YUITest.TestRunner.add(suite); }, '0.0.1', {requires: [ 'mojito-test', //test rendering utility 'mojito-markup-test' //parent mojit 'CompositeMojit', //child mojit 'ChildMojit' ]});
评论