test not running on karma/jasmine/require.js '

2019-05-03 09:17发布

问题:

I change the code, extend some functionality and add new unittest for that. Now, when I run my unit tests with karma (test framework - jasmine), it throw me an error

'There is no timestamp for /libs/angular-bootstrap/ui-bootstrap-tpls.js!'
Uncaught Error: Script error for: angular-bootstrap
http://requirejs.org/docs/errors.html#scripterror
at http://localhost:9876/base/node_modules/karma-requirejs/lib/require.js?1379984163000:138

What I'm doing wrong?

回答1:

It was my mistake completely. when using karma-requirejs you have main-test.js file where configure how to require.js get the files. I add reference to angular-bootstrap with mistake, that's why require.js couldn't find this file and throwing this mistake. So in my case this error means wrong file name provided.



回答2:

It can be because it cannot access your source file. You should configure karma to serve scripts where require will look for them. For example have the config in the karma conf

files:[{pattern: 'node_modules/**/*.js', included:false}]


回答3:

The question is old, the OP already solved his problem by now, but I'll add my two cents:

From the error message (end of the first error line) we can conclude that you were including a paths (or deps) file in main-test.js with the .js extension. In RequireJS, you need to call the file names without the extension, so your paths (or deps) would look more or less like this:

paths: {
    'ui-bootstrap': 'libs/angular-bootstrap/ui-bootstrap-tpls' // <- without the extension
}