I'm new to the concept of unit testing, and I'm trying to setup a simple test. The platform that I'm working on requires that all JavaScript be first written in CoffeeScript. I've read many examples on how to accomplish this, but my tests continuously fail.
Here is what my controller looks like:
'use strict'
angular.module('test')
.controller 'BasicController', ['$scope', '$location', ($scope, $location) ->
$scope.page.title = "Page Title"
$scope.$watch(
() ->
return $location.url()
)
]
Here is what my test script looks like:
'use strict'
describe "The Basic Controller", ->
beforeEach(module('test'))
scope = {}
location = {}
ctrl = {}
beforeEach inject ($rootScope, $controller, $location) ->
scope = $rootScope.$new()
location = $location
ctrl = $controller("BasicController", {$scope: scope})
it "should have the correct title", ->
expect(scope.page.title).toBe("Page Title")
I'm using PhantomJS and the error message that I get is that the scope.page.title object is not defined. I don't understand why this is happening. I am setting that variable to the value that the test is checking for and I'm stumped as to why it isn't passing. Any help or guidance would be greatly appreciated. I don't know if I'm making a mistake in my CoffeeScript syntax (would much rather be coding in JavaScript) or if I'm completely forgetting something.