Requirejs function in define not executed

痞子三分冷 提交于 2019-12-13 02:54:49

问题


My directory structure looks something like this:

\js
   ...
   \models\...
   ...
   \test
        \test_runner.js
        \error_test.js
        ...
   main_tests.js

Where I have the following code in main_tests.js:

requirejs(['test/test_runner'],function(){
  console.log('Testing begins');
});

The test_runner.js looks like this:

define('test_runner',['test/error_test'],function(){
   console.log("in test_runner");
});

and the error_test.js is like this:

define('error_test',['modules/error'],function() {
   console.log('in erro_test');
});

As you might have figured out I want to run from the test_runner.js some tests. I need main_tests.js in order to define the dependencies for the application to be tested. I can set up the application to work(it's ember based). When I run the code for the tests it loads the test_runner.js, but it does not execute it and it also doesn't loads its dependencies(error_test.js).

Any thoughts why it does not do the thing?


回答1:


In requireJS you've redefined 'test/test_runner' module as 'test_runner'

You should define test_runner.js without renaming the module:

define(['test/error_test'], function(){
   console.log("in test_runner");
});

As a rule of thumb, models should be referred to by their full path & name. They shouldn't be renamed by passing in the 1st param.

See the official docs



来源:https://stackoverflow.com/questions/16913268/requirejs-function-in-define-not-executed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!