samedi 31 octobre 2015

Karma Jasmine test code inside

I',m learning AngularJS and how to unit test it. (If this is a stupid question, then I'm sorry)

I'm using Karma -> Jasmine and the test works fine if I test a .js file.

Karma.conf.js

// Karma configuration
// Generated on Sat Oct 31 2015 16:45:09 GMT-0600 (CST)

...
// list of files / patterns to load in the browser
files: [
  'angular.js',
  'angular.min.js',
  'angular-mocks.js',
  'controllerSpec.js',
  'Controller.js'  //WORKS
],
....

So if I move the javascript code from the Controller.js file to a <Script> block in Controller.cshtml file

...
// list of files / patterns to load in the browser
files: [
  'angular.js',
  'angular.min.js',
  'angular-mocks.js',
  'controllerSpec.js',
  'Controller.cshtml'  //DOESN'T WORK
],
....

When I run the test Karma throws:

Uncaught SyntaxError: Unexpected tokem ILLEGAL at //Controller.cshtml:1

Is it possible to test javascript code inside <script></script> in your html file?

Aucun commentaire:

Enregistrer un commentaire