This is my first time testing in Angular and my first day at a new job. I am trying to write a test to see that the MainCtrl.lables contains something (or ideally get the values from dataRepository) Does anyone know how to do this or know any good resources for angular testing for controllers that require a service? Im having trouble finding good information for how to use mocks.
MainCtrl.js
var app = angular.module("ChartApp", ["chart.js"]);
app.controller("MainCtrl", ["$scope",
function ($scope, dataRepository) {
$scope.labels = dataRepository.labels;
$scope.data = dataRepository.data;
$scope.type = dataRepository.type;
$scope.title = dataRepository.title;
}
]);
DataSrv.js
angular.module("ChartApp")
.factory('dataRepository', function () {
return {
labels: ["Reading", "Coding", "Thinking About Coding", "Reddit", "StackOverflow"],
data: [500, 300, 300, 40, 220],
type: 'PolarArea',
title: "Angular Chart Expriment"
};
});
MainCtrlSpec.js
/// <reference path="../../Scripts/angular/angular.js" />
/// <reference path="../../Scripts/angular/angular-mocks.js" />
/// <reference path="../../Scripts/chartjs/Chart.js" />
/// <reference path="../../Scripts/angular-chart.js-master/dist/angular-chart.js" />
/// <reference path="../../Scripts/controller/main-controller.js" />
/// <reference path="../../Scripts/service/data-service.js" />
/// <reference path="../../libs/jasmine/jasmine.js" />
describe("Controller: MainCtrl", function () {
beforeEach(module("ChartApp"));
var ctrl, scope;
beforeEach(inject(function ($controller) {
scope = {};
ctrl = $controller("MainCtrl" });
}));
it("should have scope defined", function () {
expect(MainCtrl.lables).toBeDefined();
});
});
Aucun commentaire:
Enregistrer un commentaire