简体   繁体   English

运行业力+茉莉花测试时的下划线错误

[英]Underscore error when running karma + jasmine test

I'm new with frontend code testing. 我是前端代码测试的新手。 I have a strange error when running karma + jasmine tests over my js MarionetteJs app. 在我的js MarionetteJs应用程序上运行业力+茉莉花测试时出现一个奇怪的错误。 I think it might be because underscore templates are not loaded yet when I'm defining my Marionette views. 我认为这可能是因为在定义Marionette视图时,尚未加载下划线模板。

My karma.conf.js: 我的karma.conf.js:

'use strict';

module.exports = function (config) {
    config.set({
        basePath: '',
        frameworks: ['browserify', 'jasmine-ajax', 'jasmine-jquery', 'jasmine'],
        exclude: ["*.jst"],
        logLevel: 'LOG_DEBUG',
        reporters: ['progress'],
        preprocessors: {
            'tests/unit/**/test_*.js': ['browserify']
        },
        colors: true,
        browsers: ['PhantomJS'],
        singleRun: true,
        autoWatch: false,
        plugins: [
            'karma-coverage',
            'karma-browserify',
            'karma-jasmine-ajax',
            'karma-jasmine-jquery',
            'karma-jasmine',
            'karma-junit-reporter',
            'karma-phantomjs-launcher'
        ],
        browserify: {
            debug: true,
            transform: [
                'browserify-jst',
                'browserify-shim',
                'browserify-istanbul'
            ]
        },
        files: [
            'http://code.jquery.com/jquery-1.11.2.min.js',
            'tests/unit/**/test_*.js'
        ]
    });
};

This is just a dummy test that I'm trying to run: 这只是我要运行的虚拟测试:

'use strict';

var CompanyListView = require('../../company_list.js');

$(function () {
    describe("A page", function () {
        it("contains login form", function () {            
            expect(true).toBe(true);
        });
    });
});

Error happens during requiring company_list.js file: 要求company_list.js文件期间发生错误:

PhantomJS 1.9.8 (Linux 0.0.0) ERROR
  TypeError: 'undefined' is not a function (evaluating 'text.replace')
  at /tmp/082eb28c15575edda85ae0f9ce2019a6.browserify:17883:0 <- node_modules/underscore/underscore.js:1431:0

company_list.js: company_list.js:

var $ = require('jquery');
var _ = require('underscore');
var Backbone = require('backbone');
var Marionette = require('backbone.marionette');

var tplCompany = require('../templates/company_list.jst');

module.exports = Marionette.CompositeView.extend({
    template: _.template(tplCompany, {variable: 'data'}),
});

What I'm doing wrong? 我做错了什么?

Thanks for your help. 谢谢你的帮助。

The solution was in karma.conf.js: 解决方案在karma.conf.js中:

transform: [
      'browserify-jst',
      'browserify-shim',
      'browserify-istanbul'
]

Must be: 一定是:

transform: [
    ['stringify', {extensions: ['.html', '.jst'], minify: false}],
    'browserify-shim',
    'browserify-istanbul'
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在PhantomJS上运行时,业力茉莉花测试失败 - Karma jasmine test fails when running on PhantomJS 测试用例有23个时,茉莉花运行是否挂起? - Karma-jasmine running is hang when test case have 23? 测试未在karma / jasmine / require.js上运行&#39;* lib *没有时间戳!&#39; 错误 - test not running on karma/jasmine/require.js 'There is no timestamp for *lib*!' error 使用茉莉花因果与编译的打字稿测试组件时,如何解决“未定义的定义”错误? - How to resolve a “define is not defined” error when using jasmine karma with compiled typescript to test a component? 使用 Karma / Jasmine for Router 的 Angular 单元测试错误 - Unit Test error for Angular using Karma / Jasmine for Router 单元测试Karma Jasmine SyntaxError:解析“&”Angular Directive绑定时的错误 - Unit Test Karma Jasmine SyntaxError: Parse error on “&” Angular Directive binding 使用Karma和Jasmine在Subscribe中测试IF - Test IF in Subscribe using Karma and Jasmine Angular Karma Jasmine - 测试功能 - Angular Karma Jasmine - test function 在PhantomJS上运行时,Karma测试失败 - Karma test fails when running on PhantomJS 在茉莉花单元测试中使用嵌套的describe语句时,为什么业力或Webstorm崩溃? 错误:无法读取未定义的属性*? - Why is karma or Webstorm crashing when using nested describe statements in a jasmine unit test? Error: Cannot read property * of undefined?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM