Foxandxss / angular-laravel4-workflow

A workflow to use with Laravel4 and Angular
MIT License
15 stars 2 forks source link

Unit Testing: What would be the best way to integrate it? #2

Open manuelro opened 9 years ago

manuelro commented 9 years ago

First of all, thank you so much! The workflow does an amazing job merging Laravel and Angular for self consumption APIs. But I have some issues while trying to run unit tests:

I see there is a spec folder and inside it a helpers/angular-mocks.js. The testem.json file has a few options, like src_files, for example.

But when I run my tests, the gulp server throws errors like 'describe' is not defined. for my _spec.js files in the spec folder, and variable module not found which means angular-mocks.js is not loading. So for the first error it seems testem is not even loading the Jasmine Framework.

Any guidance to set this up?

My testem.json file:

{
  "framework" : "jasmine2",
  "launch_in_dev" : ["Safari"],
  "src_files" : [
    "app/js/**/*.js",
    "spec/helpers/angular-mocks.js",
    "spec/**/*_spec.js"
  ]
}
Foxandxss commented 9 years ago

How are you running it?

You need to run gulp from your angular app folder and then in another terminal gulp testem.

That should work, I just tried.

What I get is a weird error about something in angular-mock that shouldn't happen.

I need to give this workflow some work to bring bower to it which will change the testem.json a bit and see if that overrides the error.

Will keep this issue until I upgrade the workflow with the latest changes and you fix your issue.

manuelro commented 9 years ago

Yes, I ran gulp testem, it starts the test server, but none of the app/js/**/.js files seems to load, nor the Jasmine Framework, nor the angular-mocks.js, that's why the errors.

Thanks! I'll see if I can figure that out. I was also thinking about implementing the same testing workflow as in Yeoman's Angular workflow. It works fine and uses Karma and Jasmine.

manuelro commented 9 years ago

Fixed. You have to add vendor path to your testem.json file. The test engine needs the real library to be able to emulate the expected behavior with angular-mock.js. A very simple but important point.

See my new testem.json file:

{
  "framework" : "jasmine2",
  "launch_in_dev" : ["Safari"],
  "src_files" : [
    "vendor/js/**/*.js",
    "app/js/**/*.js",
    "spec/helpers/**/*.js",
    "spec/tests/**/*.js"
  ]
}
Foxandxss commented 9 years ago

Oh oh oh, I missed something on your original testem.json.

Check the default one:

{
  "framework" : "jasmine2",
  "launch_in_dev" : ["Chrome"],
  "src_files" : [
    "tmp/js/app.js",
    "spec/helpers/angular-mocks.js",
    "spec/**/*_spec.js"
  ]
}

First I add app.js and then angular-mocks.

The app.js also includes the vendor on it.

You can do it like I have on this repo or if you want to do it in your way, just make sure you add vendor before the application app.