1

I've included jasmine in an angular project and I'm trying to hook up a spec file to a file that has my angular controllers (so I can do unit tests). The problem is that I'm not entirely sure how to wire this up.

This is what the folder hierarchy for my project looks like:

project_folder/index.html
project_folder/js/controllers.js
project_folder/lib/jasmine/jasmine-standalone-2.3.4/spec/challengeSpec.js

Currently I want the tests for the controllers.js file (with the Angular code) to be in the challengeSpec.js file. How can I bring in the modules from the controllers.js file and use them in my tests? This is what some of the code from each of the files looks like:

controllers.js file:

var siteControllers = angular.module('siteControllers', []);
    fibonacciControllers.controller('pageController', ['$scope','$http', function ($scope, $http) {
    ...
});

challengeSpec.js file:

describe('siteControllers', function() {
    beforeEach(module('siteControllers'));
});

I know in the challengeSpec.js file I need to bring in the modules from the controllers.js file, but I'm not sure how this can be done. I've been doing some research that suggests I use Karma, but I'm not quite sure how this fits into the equation here. Thanks in advance.

1 Answer 1

1

Your test spec seems to be on a good start, but you should not put the file in the place you did. Using Karma is needed as it is the 'test runner'. For a completer story from a-z I'd try reading this https://www.airpair.com/angularjs/posts/unit-testing-angularjs

Sign up to request clarification or add additional context in comments.

2 Comments

So there's no way to use Jasmine alone? What would the standalone Jasmine framework be for then, just for vanilla javascript and no framework?
right. Karma knows about AngularJs specifics like promises, which is why you use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.