使用茉莉花测试木偶视图和车把模板

Testing Marionette View and Handlebars template with Jasmine

本文关键字:视图 茉莉花 测试      更新时间:2023-09-26

我正在尝试测试骨干应用程序。
当我需要测试一个简单的主干网时,我没有问题。
如果我需要使用Backbone.Marionette(项目视图或复合视图)测试主干视图,并且Handlebars template收到以下消息:

NoTemplateError: Could not find template: 
function(context, options) {
    if (!compiled) {
      compiled = compile();
    }
    return compiled.call(this, context, options);
  };

关于function(context, options)的代码来自handlebars-1.0.0.beta.6.js
知道如何修复代码吗?

这是我正在执行的测试:

describe("AppViewMarionette", function() {
    beforeEach(function(){
        this.view = new AppViewMarionette();
    });
    describe("Rendering", function () {
        it("returns the view object", function () {
            expect(this.view.render()).toEqual(this.view);
        });
    });
});

您需要更新木偶版本。 v0.9.1 不支持将预编译模板直接分配给template设置。为此,您需要 v0.9.7 或更高版本。

如果您无法更新,则需要按照以下说明使其正常工作:https://github.com/derickbailey/backbone.marionette/wiki/Using-pre-compiled-templates