通過使用jasmine
,我試圖測試一個JavaScript模塊,它返回一個Marionette.CompositeView
。單元測試與Marionette.CompositeView
這裏是javascript模塊(2)和javascript單元測試(1)。
我的問題是如何訪問從(1)呈現的視圖?
有關更多詳細信息,請參閱代碼註釋。
P.S .:
1)javascript模塊可以生成正確的渲染視圖。
2)當我運行測試,JavaScript控制檯使我有以下錯誤:backbone.marionette.min.js:9
Uncaught NoTemplateError: Could not find template: 'function (context, options) {
if (!compiled) {
compiled = compile();
}
return compiled.call(this, context, options);
}'
3)由於我使用的handlebars
我重寫這樣的Marionette.Renderer.render
:
enter code here
define([
'marionette'
], function (Marionette) {
Marionette.Renderer.render = function (template, data) {
return template(data);
};
});
(1)
(function() {
'use strict';
define([
// some code
], function (MyView) {
describe('Layout App - Header View ', function() {
beforeEach(function() {
this.view = new MyView({
currentUser: new Backbone.Model()
});
});
describe('Instantiation', function() {
it('should create a div element', function() {
expect(this.view.el.nodeName).toEqual('DIV'); // it works
});
});
describe("Rendering", function() {
it("returns the view object", function() {
console.log(this.view.render()); // undefined // why?
expect(this.view.render()).toEqual(this.view); // it fails
});
});
});
});
});
(2)
define([
// some code
], function (myTemplate, MyItemView) {
return Marionette.CompositeView.extend({
template: myTemplate,
itemView: MyItemView,
// some code
});
});
嗨德里克,感謝您的回覆。其實,你的建議並沒有解決這個問題。無論如何,我添加了更多關於我的問題的信息請參閱「P.S.」部分,第2和第3點 – 2012-08-14 12:37:24