diff --git a/demo/index.html b/demo/index.html
index 438d74e..f9d113a 100644
--- a/demo/index.html
+++ b/demo/index.html
@@ -18,7 +18,7 @@
AngularJS Environment Plugin
Let's see if it works
- The current environment is {{environment}} and this are the their vars
+ The current environment is {{environment}} and this is their vars
diff --git a/karma.conf.js b/karma.conf.js
new file mode 100644
index 0000000..dde99ca
--- /dev/null
+++ b/karma.conf.js
@@ -0,0 +1,21 @@
+module.exports = function (config) {
+ config.set({
+ plugins: [
+ 'karma-jasmine',
+ 'karma-chrome-launcher'
+ ],
+ frameworks: ['jasmine'],
+ singleRun: false,
+ autoWatch: true,
+ colors: true,
+ reporters: ['dots'],
+ browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'],
+ files: [
+ 'node_modules/angular/angular.js',
+ 'node_modules/angular-mocks/angular-mocks.js',
+ 'src/angular-environment.js',
+ 'test/*.js'
+ ],
+ logLevel: config.LOG_ERROR
+ });
+};
diff --git a/package.json b/package.json
index 0624e42..b2c618a 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,9 @@
"version": "1.0.8",
"description": "AngujarJS Environment Plugin",
"main": "index.js",
+ "scripts": {
+ "test": "karma start --single-run"
+ },
"repository": {
"type": "git",
"url": "git+https://github.com/juanpablob/angular-environment.git"
@@ -28,6 +31,7 @@
},
"devDependencies": {
"angular": ">1.2.0",
+ "angular-mocks": ">1.2.0",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-jshint": "^1.11.2",
@@ -37,6 +41,12 @@
"gulp-strip-debug": "^1.1.0",
"gulp-util": "^3.0.6",
"gulp-watch": "^4.3.3",
+ "jasmine": "^2.6.0",
+ "jasmine-core": "^2.6.1",
+ "karma": "^1.6.0",
+ "karma-chrome-launcher": "^2.0.0",
+ "karma-firefox-launcher": "^1.0.1",
+ "karma-jasmine": "^1.1.0",
"yargs": "^3.15.0"
}
}
diff --git a/test/angular-environment.js b/test/angular-environment.js
new file mode 100644
index 0000000..666745f
--- /dev/null
+++ b/test/angular-environment.js
@@ -0,0 +1,56 @@
+'use strict';
+
+describe('Test environment provider', function () {
+
+ var theEnvServiceProvider;
+ var envService;
+
+ beforeEach(function () {
+ // Initialise the provider by injecting it into a fake module's
+ // config block.
+ var fakeModule = angular.module('test.app.environment', []);
+ fakeModule.config(function (envServiceProvider) {
+ theEnvServiceProvider = envServiceProvider;
+ });
+ // Initialise the test.app injector.
+ module('environment', 'test.app.environment');
+ inject(function () {});
+ envService = theEnvServiceProvider.$get();
+
+ envService.config({
+ vars: {
+ development: {
+ backend: 'https://backend-dev/'
+ },
+ production: {
+ backend: 'https://backend/'
+ }
+ }
+ });
+ });
+
+ describe('with envService provider', function () {
+ it('tests the envService provider can be created', function () {
+ expect(theEnvServiceProvider).toBeDefined();
+ });
+
+ it('tests the default environment for envService is development', function () {
+ expect(envService.environment).toBe('development');
+ expect(envService.get()).toBe('development');
+ });
+
+ it('tests the environment for envService can be set', function () {
+ envService.set('production');
+ expect(envService.get()).toBe('production');
+ });
+
+ it('tests the config var for development environment is selected', function () {
+ expect(envService.read('backend')).toBe('https://backend-dev/');
+ });
+
+ it('tests the config var for production environment is selected', function () {
+ envService.set('production');
+ expect(envService.read('backend')).toBe('https://backend/');
+ });
+ });
+});