问题
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