Skip to content

Commit

Permalink
Merge pull request #27 from rars/add-unit-tests
Browse files Browse the repository at this point in the history
Add start of unit tests
  • Loading branch information
juanpablob authored Apr 30, 2017
2 parents 34c40c6 + 1ebc8b2 commit ec46f48
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<h1>AngularJS Environment Plugin</h1>
<p>Let's see if it works</p>
<hr>
<h3>The current environment is <span style="color: blue;">{{environment}}</span> and this are the their vars</h3>
<h3>The current environment is <span style="color: blue;">{{environment}}</span> and this is their vars</h3>
<ul>
<li ng-repeat="(k, v) in vars"><code>{{k}} —→ {{v}}</code></li>
</ul>
Expand Down
21 changes: 21 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -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
});
};
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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"
}
}
56 changes: 56 additions & 0 deletions test/angular-environment.js
Original file line number Diff line number Diff line change
@@ -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/');
});
});
});

0 comments on commit ec46f48

Please sign in to comment.