Angular Uncaught RefereneError: module is not defined
Trying to write what may be considered to be a straightforward test. But
the purpose of this test is to read in a json file and check the field
name and check if it exist. My first initial go at writing this. I have
the following:
test\unit\controllers\main.js
'use strict';
// load the controller's module
beforeEach(module('sufi'));
describe('MainCtrl', function() {
var MainCtrl, scope, httpBackend;
// Initialize the controller and a mock scope
beforeEach(inject(function($controller, $rootScope, $httpBackend) {
// Set up the expected data
httpBackend = $httpBackend;
$httpBackend.expectGET('test/mock/coffeeSample.json').
respond({name: 'ESPRESSO RISTRETTO'});
scope = $rootScope.$new();
MainCtrl = $controller('MainCtrl', {
$scope: scope
});
}));
});
test\unit\mock\coffeeSample.js
[
{
"id":"",
"name":"ESPRESSO RISTRETTO",
"image":"",
"type":"Intense",
"temp":"",
"caffeinated":"",
"basicInfo":"Delightfully short for a bolder fuller flavour."
},
{
"id":"",
"name":"GRANDE INTENSO",
"image":"",
"type":"Intense",
"temp":"",
"caffeinated":"",
"basicInfo":"A mug of bold, full-bodied coffee – enjoy with or without
milk."
},
{
"id":"",
"name":"LUNGO INTENSO",
"image":"",
"type":"Intense",
"temp":"",
"caffeinated":"",
"basicInfo":"The more intense version of the 'stretched' espresso.
Enjoy with or without milk."
},
{
"id":"",
"name":"MARRAKESH STYLE TEA",
"image":"",
"type":"Unexpected",
"temp":"",
"caffeinated":"",
"basicInfo":"A blend of aromatic green tea, intensely flavourful and
refreshing mint, topped with NESCAFÉ® Dolce Gusto's infamous mousse
and sweetened to perfection."
},
{
"id":"",
"name":"MOCHA",
"image":"",
"type":"Chocolatey",
"temp":"",
"caffeinated":"",
"basicInfo":"Rich coffee with a delightful chocolate twist."
}
]
app/assets/javascript/application.js
// Libaries
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require angular
//= require angular-resource
//= require_self
// Application Related Stuff
//= require controllers/main
//= require controllers/global
//= require directives/main
//= require directives/global
//= require filters/main
//= require filters/global
//= require services/main
//= require services/global
//= require routes
app = angular.module("sufi");
In the main index page I have the following which is being written in haml.
!!!
%html(ng-app="sufi")
%head
%meta{:content => "width=device-width, initial-scale=1.0", :name =>
"viewport"}
%title= content_for?(:title) ? yield(:title) : "Sufi"
%meta{:content => content_for?(:description) ? yield(:description) :
"Sufi", :name => "description"}
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
= yield(:head)
%body{:class => "#{controller_name} #{action_name}"}
.navbar.navbar-fixed-top
%nav.navbar-inner
.container
= render 'layouts/navigation'
#main{:role => "main"}
.container
.content
.row
.span12
= render 'layouts/messages'
= yield
%footer
/ ! end of .container
/ ! end of #main
My question is why when I run Karma run I am getting an Uncaught
ReferenceError: module is not defined and this points to my
test\unit\controllers\main.js:4
beforeEach(module('sufi'));
Is this not correct the way I have defined this?
No comments:
Post a Comment