4

I can't get Angular mocks or angular itself to be recognized in an sbt-web / sbt-mocha project.

I was writing a sample based on the sbt-web play http://typesafe.com/activator/template/play-2.3-highlights highlights sample. I killed the other plugins but left the sbt-mocha one.

I declared the dependencies in libraryDependencies:

libraryDependencies ++= Seq(
  "org.webjars" % "jquery" % "2.1.0-2",
  "org.webjars" % "angularjs" % "1.3.0-beta.18",
  "org.webjars" % "angular-ui-router" % "0.2.10-1",
  "org.webjars" % "squirejs" % "0.1.0" % "test",
  "org.webjars" % "chai" % "1.9.1" % "test"
)

I then wrote an angular app with a constant and dropped it in assets/javascripts as app.js:

angular.module('myApp', [])
  .constant('PI', Math.PI);

Next, I wrote a test:

(function() {
'use strict';

    describe('angular spec', function() {
        beforeEach(module('myApp'));

        it('should have an app with PI', inject(function(PI) {
            expect(PI).to.be.defined();
        }));
    });
}());

I then fired up sbt mochaOnly and got:

[error] TypeError: module is not a function, it is object. 

Now, I've tried using angular.mocks.module as well and it gives me an error that Angular doesn't exist.

I also added the same library to the test path, thinking maybe the test path was isolated from the main one, (silly idea) but that didn't help. I then tried following http://www.scala-js.org/doc/sbt/depending.html to include only the mocks js file like this:

  "org.webjars" % "angularjs" % "1.3.0-beta.18" / "angular-mocks.js" % "test",

But it gave me an error around the "/" and didn't recognize it, so strike three...

I've done this dozens and dozens of times with gulp, grunt, even maven with the maven-jasmine-plugin but now I'm in sbt-web world, and it uses mocha, and there isn't any documentation to go on. I'm also new to Scala and would like to try to get something going, so apologies if I don't get it yet... Very possible!

I just want to bootstrap the angular mocks library with the module function, and then inject an angular asset like PI with inject.

I have a GitHub repo with this code in it... it is : https://github.com/krimple/sbt-web-project-with-angular/

Anyone want to hack on this with me? I'd love to figure it out and do a pull request for the play seed project for angular so that we actually have some mocha tests. Even better would be a jasmine sbt plugin but I think we're going to have to focus on mocha first.

Michael Zajac
  • 55,144
  • 7
  • 113
  • 138
Ken Rimple
  • 126
  • 6
  • Also I got a strange message about how I can't create a question with the tag sbt-mocha unless I have a rating of 1500 or higher. WHAT? How are you supposed to get help on a topic if the topic is so rarified that you can't ask a question?? Sorry, that was annoying. – Ken Rimple Aug 18 '14 at 12:48
  • Interestingly, with a console.log, it looks like the "module" is something that represents the mocha "module under test". angular.mocks.module isn't available so the script isn't getting included. – Ken Rimple Aug 18 '14 at 13:03
  • I updated the git repository and included an assets/app.html, along with an assets/javascripts/app.js sample. I was able to get Angular working without the asset pipelining work (just by referencing assets/lib) but that's not ideal. At least I can move forward but it would be nice to get the pipelining working and the testing in mocha functional. – Ken Rimple Aug 18 '14 at 22:03
  • Looks more promising to use another github project as a guide - I'm looking now at https://github.com/mariussoutier/play-angular-require-seed and the only thing it lacks is the sbt-mocha plugin. BUT it does have a good requirejs example of importing the angular libraries and it works out of the box. Once I get a full working stack I'll answer my question myself and close this out. – Ken Rimple Aug 20 '14 at 22:24

1 Answers1

1

You lack a dependency:

"org.webjars" %% "webjars-play" % "2.3.0"

See if that's the issue.

Roger
  • 2,912
  • 2
  • 31
  • 39