Skip to content

Commit

Permalink
Added unit test for controller using the regServices. This closes #27
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos Lin committed May 28, 2014
1 parent cf8c0ff commit c40bc19
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
7 changes: 4 additions & 3 deletions test/unit/lib/main.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ require.config({
'app_no_ngload': 'test/unit/lib/app_no_ngload',
'services': 'test/unit/lib/services',
'regServices': 'test/unit/lib/regServices',
'controller': 'test/unit/lib/controller'
'controller': 'test/unit/lib/controller',
'regController': 'test/unit/lib/regController'
},

shim: {
Expand All @@ -32,8 +33,8 @@ require.config({
*/
'test/unit/regServices.spec': ['test/unit/app.spec'],
'test/unit/services.spec': ['test/unit/regServices.spec'],
'test/unit/controller.spec': ['test/unit/services.spec']
'test/unit/regController.spec': ['test/unit/services.spec'],
'test/unit/controller.spec': ['test/unit/regController.spec'],
},

Expand Down
19 changes: 19 additions & 0 deletions test/unit/lib/regController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*jslint nomen: true */
/*globals define, angular */

define(['app','regServices'], function (app) {
'use strict';
var ctrl_name = "RegController";
app.register.controller(ctrl_name, ['$scope', 'UtestRegFactory', 'UtestRegService', function ($scope, UtestRegFactory, UtestRegService) {
$scope.ctrl_name = ctrl_name;
$scope.utest_reg_factory = UtestRegFactory;
$scope.utest_reg_service = UtestRegService;
}]);

// Return expected unit test result
app.__utest_ctrl_result = {
"ctrl_name": ctrl_name
};

return app;
});
5 changes: 5 additions & 0 deletions test/unit/lib/regServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ define(['app', 'angularAMD'], function(app, angularAMD) {
};
});

// Return the result in a factory
services.factory('UtestRegServiceResult', function () {
return utest_reg_result;
});

// Return expected unit test result
app.__utest_regserv_result = utest_reg_result;

Expand Down
2 changes: 0 additions & 2 deletions test/unit/lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@
};
});


// Return the result in a factory
services.factory('UtestServiceResult', function () {
return utest_result;
});


// Return the result of Utester
services.factory('configUtestResult', function (configUtest) {
return configUtest.getValue();
Expand Down
42 changes: 42 additions & 0 deletions test/unit/regController.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*jslint browser: true, devel: true, node: true, nomen: true */
/*globals define, angular, describe, expect, it */

/**
* Testing declaration of controller following require.js spec and make sure
* it's dependecies are loaded.
*/
define(['regController', 'angularAMD'], function (app, angularAMD) {
'use strict';
describe('Utest RegController', function () {
//console.log("Running controllerSpec.js");
var ctrl_name = app.__utest_ctrl_result.ctrl_name,
scope, service_results, ctrl;

angularAMD.inject(function ($rootScope, $controller, UtestRegServiceResult) {
scope = $rootScope.$new();
service_results = UtestRegServiceResult;
ctrl = $controller(ctrl_name, { $scope: scope });
});

it("service_results should exists.", function () {
expect(service_results).toBeDefined();
});

it("scope.ctrl_name check", function () {
expect(scope.ctrl_name).toBe(ctrl_name);
});

it("scope.utest_factory check", function () {
var f = scope.utest_reg_factory;
expect(f.name).toBe(service_results.factory_name);
expect(f.const_name).toBe(service_results.reg_constant_name);
});

it("scope.utest_service check", function () {
var s = scope.utest_reg_service;
expect(s.name).toBe(service_results.service_name);
expect(s.val_name).toBe(service_results.reg_value_name);
});

});
});

0 comments on commit c40bc19

Please sign in to comment.