marcoslin / angularAMD

Facilitate use of RequireJS in AngularJS
http://marcoslin.github.io/angularAMD
MIT License
734 stars 171 forks source link

Karma + Jasmine 2.x issues #106

Closed adrianduke closed 10 years ago

adrianduke commented 10 years ago

Hi,

I'm trying to use angularAMD inside my angular project but keep butting up against issues in regards to injecting and unit tests. It appears to be related to jasmine 2.0, so I went ahead and pulled the marcoslin/angularAMD-karma repo and upgraded:

When I ran the tests I got the following:

INFO [karma]: Karma v0.12.24 server started at http://localhost:2080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket _f_OFlFdJ80jRXzgD7jE with id 28012063
PhantomJS 1.9.7 (Mac OS X) home-controller.js app should be defined. FAILED
    Error: angularAMD not initialized.  Need to call angularAMD.bootstrap(app) first.
        at checkBootstrapped (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/bower_components/angularAMD/angularAMD.js:34)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/bower_components/angularAMD/angularAMD.js:296
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/www/js/home_controller_test.js:12
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/karma-jasmine/lib/boot.js:117
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/karma-jasmine/lib/adapter.js:171
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1658
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:874
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1151
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:782
        at callGetModule (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1178)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1552
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1679
PhantomJS 1.9.7 (Mac OS X) home-controller.js should have scope.message string in controller FAILED
    Error: angularAMD not initialized.  Need to call angularAMD.bootstrap(app) first.
        at checkBootstrapped (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/bower_components/angularAMD/angularAMD.js:34)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/bower_components/angularAMD/angularAMD.js:296
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/www/js/home_controller_test.js:12
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/karma-jasmine/lib/boot.js:117
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/karma-jasmine/lib/adapter.js:171
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1658
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:874
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1151
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:782
        at callGetModule (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1178)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1552
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1679
    TypeError: 'undefined' is not an object (evaluating 'scope.message')
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/www/js/home_controller_test.js:20
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/karma-jasmine/lib/boot.js:117
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/karma-jasmine/lib/adapter.js:171
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1658
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:874
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1121
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:132
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1164
        at each (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:57)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1165
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:925
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1151
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:782
        at callGetModule (/Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1178)
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1552
        at /Volumes/CaseSensitive/Development/requirejs/angularAMD-karma/node_modules/requirejs/require.js:1679
PhantomJS 1.9.7 (Mac OS X): Executed 3 of 3 (2 FAILED) (0.009 secs / 0.002 secs)

These errors are different to what I am experiencing with my code base, but I will put them in a separate issue.

Thanks, Adrian

marcoslin commented 10 years ago

Thanks for reporting the problem.

The root cause is that the test should really be waiting for angularAMD's bootstrap to take place, which happens after the document.ready event. I updated the angularAMD-karma project to use Jasmine 2.0 and added needed wait.

mpiasta-ca commented 10 years ago

@marcoslin I just tried upgrading to Jasmine 2 from Jasmine 1.5 and it broke all my tests. Couldn't get it working, threw same error as original poster. When I added 'angularAMD': ['angular'] into shims, it kept timing out. Couldn't get it working and had to revert to Jasmine 1.5 again.

What did you change in angularAMD-karma to make it work with Jasmine 2.0, was it specifically the interval method in the app_test.js file?

marcoslin commented 10 years ago

@mpiasta-ca yes, the key was the interval method in the app_test.js. I just pushed a new version adding directive testing as per #111.