diff --git a/test/unit/lib/main.mustache b/test/unit/lib/main.mustache index d10877f..a65efc0 100644 --- a/test/unit/lib/main.mustache +++ b/test/unit/lib/main.mustache @@ -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: { @@ -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'], }, diff --git a/test/unit/lib/regController.js b/test/unit/lib/regController.js new file mode 100644 index 0000000..1751aa9 --- /dev/null +++ b/test/unit/lib/regController.js @@ -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; +}); diff --git a/test/unit/lib/regServices.js b/test/unit/lib/regServices.js index d6e8eb6..0d329b8 100644 --- a/test/unit/lib/regServices.js +++ b/test/unit/lib/regServices.js @@ -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; diff --git a/test/unit/lib/services.js b/test/unit/lib/services.js index 4651ea4..c9e118b 100644 --- a/test/unit/lib/services.js +++ b/test/unit/lib/services.js @@ -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(); diff --git a/test/unit/regController.spec.js b/test/unit/regController.spec.js new file mode 100644 index 0000000..8941576 --- /dev/null +++ b/test/unit/regController.spec.js @@ -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); + }); + + }); +});