preboot / angularjs-webpack

A complete, yet simple, starter for AngularJS using webpack
MIT License
1.71k stars 658 forks source link

Include .spec files with working example #16

Closed ajcrites closed 8 years ago

ajcrites commented 8 years ago

I am trying to get karma + webpack + angular working based on your examples, but you do not have any .spec file examples in the repo to confirm how things should be working. I'm currently unable to get a spec working. The app I've created works fine and I can get the tests to run, but no matter what I do I keep coming back to:

Argument 'NgculatorCtrl' is not a function, got undefined

I also tried cloning this repo and adding an simple app.spec file but it seems like it doesn't get webpacked (it will complain if I try to use an arrow function).

npm test will also complain if you try to use beforeEach(module('app')). I think this may be related to my problem.

I've created a gist that includes my relevant karma/webpack/test config files as well as the sample test I am trying to run

The test will run, but I get various errors at the $controller call. I've tried all of the following:

  1. Added myapp/index.js to the test.webpack.js file so that it loads the module. I also have to remove import 'angular'; from that file. This yields the same error.
  2. Then, adding beforeEach(module('myapp')) to any test -- yields Object is not a function (evaluating 'module('myapp')'). If I do angular.module('myapp') I don't get an error. angular.module('notmyapp') does emit an error.
  3. I've tried importing angular-mocks right after importing angular in the entry point file just in case importing it after defining modules has an effect. It doesn't seem like this matters ... nothing changes.

If you could include a working version of a test it would help me out -- especially if you can include specifics about where I am going wrong. It seems to me that you would also have to include your source files and not just the .spec/test files so that your module is loaded, but then I'm not sure why module('myapp') doesn't work in tests.

zombiQWERTY commented 8 years ago

@ajcrites try this one https://gist.github.com/zombiQWERTY/f01087f01506f67d4126

Foxandxss commented 8 years ago

You are pretty much right my friend. I always relied on the demo but that is not good enough (I don't even have it linked in the new readme).

I will add a little extra code tomorrow for this.

Foxandxss commented 8 years ago

I created a minimal application with a spec file. Check it out ;)

ajcrites commented 8 years ago

This is great! One thing that is weird is that I tried emulating this but I had to specify the babel loader for isparta-instrumenter, but you don't do this in your code. How is isparta-instrumenter able to work with the ES6 files for you?

Foxandxss commented 8 years ago

There is a loader setup on webpack (that gets processed on test mode) and then some coverage config on karma.

Check the webpack part.