Watt
Watt

Reputation: 3164

Beginner guide to test AngularJS controllers

Can someone please point me to a resource, where I can get a Beginner tutorial on how to write unit test for AngularJS controller?

I have never written any test for JavaScript before. But, very experienced with jUnit test in core java.

I have found tons of resources over internet talking about testing JavaScript, but most of them pre-assume that I have done some javascript testing before or I am an expert on some javascript testing API.

For instance:

I didn't find this useful, couldn't run any test. Don't know from where to download angular-mocks.js and what is coffescript. I was thinking we just need to have Jasmine JS to test an angularJS controller.

And Running AngularJS Test runs fine locally and is very detailed, but don't know how to test my simple controller using any of it.

Similarly I have gone through many such less than helpful (for me) tutorial and didn't go anywhere.

To make this question further specific. Suppose I have a controller like below

app.controller('abcController', function ($scope, $log, abcFactory {
    init();

    function init() {
        $scope.testVar="this is a test"
        }
    }); 

I just want to test if $scope.testVar value is set to "This is a test" or not. That is it!!

How to do that. Please don't write snippet of code, if possible please walk me through how to set all the files to get this test setup.

Upvotes: 3

Views: 627

Answers (1)

arussinov
arussinov

Reputation: 1237

Yes, you can do it with Jasmin, I have created a plunk to illustrate how it works, I think after you will get it. My link Really what you need is correctly bootstrap Jasmin.

Upvotes: 2

Related Questions