【问题标题】:"define is not defined" - jasmine-node requirejs in Nodejs“未定义定义”-Nodejs 中的 jasmine-node requirejs
【发布时间】:2019-01-17 05:26:18
【问题描述】:

我正在尝试对使用 requirejs 的文件运行 jasmine 测试。我有一个 require.config.js 文件,它提供了 requirejs 的所有配置,我正在传递给这个命令来运行 jasmine 测试。

jasmine-node --runWithRequireJs --captureExceptions --requireJsSetup spec/require.config.js spec/modules/test.spec.js

我的 require.config.js 看起来像这样 -

var require = {
    baseUrl: "../app",
      urlArgs: 'cb=' + Math.random(),
      paths: {
        jquery: '../assets/js/libs/jquery-1.8.2',
        underscore: '../assets/js/libs/underscore-min',
        backbone: '../assets/js/libs/backbone-min',
        jasmine: '../spec/lib/jasmine',
        jasminehtml: '../spec/lib/jasmine-html',
        boot: '../spec/lib/boot',
        spec: '../spec/',
        handlebars : '../assets/js/libs/handlebars-1.0.0.beta.6',

        // plugins
        jqueryui : '../assets/js/plugins/jquery-ui',
        jqgrid : '../assets/js/plugins/jqGrid',
        jqgridlocale : '../assets/js/plugins/i18n/grid.locale-en',
        jqform : '../assets/js/plugins/jquery.form',
        jqfiledownload : '../assets/js/plugins/jquery.fileDownload',
        migrate: '../assets/js/plugins/jquery-migrate',
        text : '../assets/js/plugins/text'
      },
      shim: {
        'underscore': {
          exports: "_"
        },
        'backbone': {
          deps: ['underscore', 'jquery'],
          exports: 'Backbone'
        },
        'jasmine': {
          exports: 'jasmine'
        },
        'jasminehtml': {
          deps: ['jasmine'],
          exports: 'jasmine'
        },
        'boot': {
          deps: ['jasmine', 'jasminehtml'],
          exports: 'window.jasmineRequire'
        },
        'handlebars' : {
                exports : 'Handlebars'
        },
        'text' : {
            exports : 'text'
        },
        'jqueryui' : [ 'jquery' ],
        'jqgrid' : [ 'jquery' ],
        'jqgridlocale' : [ 'jquery' ],
        'jqform':['jquery'],
        'jqfiledownload':['jquery'],
        'migrate':['jquery']
      }};

我的 test.spec.js 文件看起来像这样 -

define(['modules/models/RouteModel','modules/models/RestWebService'], function(RouteModel,RestWebService){

describe("RouteModel :", function(){
    it("should create an test instance", function(){
        expect(RouteModel).not.toBe(null);
    });
});

运行命令后我进入控制台

ReferenceError: define is not defined at C:\Users\TestProject\spec\modules\test.spec.js:1:1

在这种情况下可能会出现什么问题?这是路径配置问题吗?

附: - 我想要 jasmine 的完整控制台输出,而不是 jasmine 中的浏览器输出。

【问题讨论】:

    标签: node.js jasmine requirejs jasmine-node


    【解决方案1】:

    错误非常简单,您需要在调用它的函数之前加载 requirejs。您可以从以下链接中找到更清晰的想法: https://stackoverflow.com/a/29317859/1607130

    【讨论】:

    • 感谢您的回复。我在发布之前浏览了这个链接,但我不想通过浏览器运行 jasmine。如果我通过浏览器运行,我会得到输出,因为我所有的测试都通过了。但我想通过npm 命令或在本例中为jasmine-node 获得输出。在这种情况下,我收到 define is not defined 错误。
    • 实际上我的目标是完整的控制台输出,所以与SpecRunner.html 相关的任何内容都对我的情况没有帮助。
    猜你喜欢
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-08-23
    • 2017-09-25
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    相关资源
    最近更新 更多