Skip to content

Commit 0f6b98a

Browse files
committed
Added first tests.
1 parent c917810 commit 0f6b98a

File tree

4 files changed

+84
-7
lines changed

4 files changed

+84
-7
lines changed

gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ gulp.task('lint', ['jshint', 'csslint', 'scsslint']);
250250
gulp.task('test', ['templates'], function() {
251251
return testFiles()
252252
.pipe(g.karma({
253-
configFile: 'karma.conf.js',
254-
action: 'run'
253+
configFile: __dirname + '/karma.conf.js',
254+
singleRun: true
255255
}))
256256
;
257257
});

karma.conf.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
module.exports = function ( karma ) {
3-
process.env.PHANTOMJS_BIN = 'node_modules/karma-phantomjs-launcher/node_modules/.bin/phantomjs';
3+
process.env.PHANTOMJS_BIN = 'node_modules/phantomjs/bin/phantomjs';
44

55
karma.set({
66
/**
@@ -14,13 +14,13 @@ module.exports = function ( karma ) {
1414
files: [
1515
],
1616

17-
frameworks: [ 'mocha', 'chai' ],
18-
plugins: [ 'karma-mocha', 'karma-chai', 'karma-phantomjs-launcher' ],
17+
frameworks: [ 'mocha', 'chai', 'sinon-chai' ],
18+
plugins: [ 'karma-mocha', 'karma-mocha-reporter', 'karma-chai', 'karma-sinon-chai', 'karma-phantomjs-launcher' ],
1919

2020
/**
2121
* How to report, by default.
2222
*/
23-
reporters: 'progress',
23+
reporters: 'mocha',
2424

2525
/**
2626
* Show colors in output?

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"connect-history-api-fallback": "1.1.0"
1616
},
1717
"devDependencies": {
18+
"chai": "3.4.1",
1819
"event-stream": "3.3.2",
1920
"gulp": "3.9.0",
2021
"gulp-angular-filesort": "1.1.1",
@@ -46,8 +47,14 @@
4647
"karma-chai": "0.1.0",
4748
"karma-chrome-launcher": "0.2.1",
4849
"karma-mocha": "0.2.0",
50+
"karma-mocha-reporter": "^1.1.1",
51+
"karma-phantomjs-launcher": "0.2.1",
52+
"karma-sinon-chai": "1.1.0",
4953
"lazypipe": "1.0.1",
50-
"main-bower-files": "^2.9.0",
54+
"main-bower-files": "2.9.0",
55+
"mocha": "2.3.3",
56+
"phantomjs": "1.9.18",
57+
"sinon": "^1.17.2",
5158
"sort-stream": "1.0.1",
5259
"streamqueue": "1.1.1",
5360
"tiny-lr": "0.2.1"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* jshint strict:false, globalstrict:false */
2+
/* global describe, it, beforeEach, inject, module */
3+
describe('ChatController', function() {
4+
var ChatController;
5+
var scope;
6+
var timeout;
7+
var localStorage;
8+
var MessageService;
9+
var MessageModel;
10+
var _messages;
11+
var sandbox;
12+
13+
beforeEach(module('frontend'));
14+
15+
beforeEach(inject(function($injector) {
16+
scope = $injector.get('$rootScope');
17+
timeout = $injector.get('$timeout');
18+
localStorage = $injector.get('$localStorage');
19+
MessageService = $injector.get('MessageService');
20+
MessageModel = $injector.get('MessageModel');
21+
_messages = [];
22+
sandbox = sinon.sandbox.create();
23+
24+
ChatController = function() {
25+
return $injector.get('$controller')('ChatController', {
26+
$scope: scope,
27+
$timeout: timeout,
28+
$localStorage: localStorage,
29+
MessageService: MessageService,
30+
MessageModel: MessageModel,
31+
_messages: _messages
32+
});
33+
};
34+
}));
35+
36+
afterEach(function() {
37+
sandbox.restore();
38+
});
39+
40+
it('should have specified defaults', function() {
41+
ChatController();
42+
43+
expect(scope.messages).to.be.an('array');
44+
expect(scope.nick).equal('');
45+
expect(scope.message.nick).equal('');
46+
expect(scope.message.message).equal('');
47+
});
48+
49+
describe('When entering chat', function() {
50+
it('with nick', function() {
51+
ChatController();
52+
53+
scope.nick = 'test nick';
54+
scope.enterToChat();
55+
56+
expect(scope.message.nick).equal('test nick');
57+
});
58+
59+
it('without nick', function() {
60+
ChatController();
61+
62+
sandbox.stub(MessageService, 'error');
63+
64+
scope.nick = '';
65+
scope.enterToChat();
66+
67+
expect(MessageService.error.calledOnce).to.equal(true);
68+
});
69+
});
70+
});

0 commit comments

Comments
 (0)