Skip to content

Commit f465d23

Browse files
gbmeowValentin Hervieu
authored andcommitted
setup tests
1 parent 4ebb630 commit f465d23

File tree

4 files changed

+118
-7
lines changed

4 files changed

+118
-7
lines changed

Gruntfile.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
module.exports = function(grunt) {
1+
module.exports = function (grunt) {
22
// Project configuration.
33
grunt.initConfig({
44

55
pkg: grunt.file.readJSON('package.json'),
66

77
minBanner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
8-
'(c) <%= pkg.author %>, <%= pkg.repository.url %> - ' +
9-
'<%= grunt.template.today("yyyy-mm-dd") %> */\n',
8+
'(c) <%= pkg.author %>, <%= pkg.repository.url %> - ' +
9+
'<%= grunt.template.today("yyyy-mm-dd") %> */\n',
1010

1111
recess: {
1212
options: {
@@ -58,10 +58,10 @@ module.exports = function(grunt) {
5858
removeStyleLinkTypeAttributes: true
5959
},
6060
module: 'rzModule',
61-
url: function(url) {
61+
url: function (url) {
6262
return url.replace('src/', '');
6363
},
64-
bootstrap: function(module, script) {
64+
bootstrap: function (module, script) {
6565
return 'module.run(function($templateCache) {\n' + script + '\n});';
6666
}
6767
}
@@ -118,8 +118,13 @@ module.exports = function(grunt) {
118118
options: {
119119
port: 9000
120120
}
121+
},
122+
karma: {
123+
unit: {
124+
configFile: 'karma.conf.js',
125+
singleRun: true
126+
}
121127
}
122-
123128
});
124129

125130
grunt.loadNpmTasks('grunt-contrib-uglify');
@@ -129,8 +134,10 @@ module.exports = function(grunt) {
129134
grunt.loadNpmTasks('grunt-ng-annotate');
130135
grunt.loadNpmTasks('grunt-contrib-watch');
131136
grunt.loadNpmTasks('grunt-serve');
137+
grunt.loadNpmTasks('grunt-karma');
132138

133139
grunt.registerTask('default', ['css', 'js']);
140+
grunt.registerTask('test', ['karma']);
134141

135142
grunt.registerTask('css', ['recess']);
136143
grunt.registerTask('js', ['ngtemplates', 'replace', 'ngAnnotate', 'uglify']);

karma.conf.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
3+
module.exports = function (config) {
4+
config.set({
5+
// base path, that will be used to resolve files and exclude
6+
basePath: '',
7+
8+
// testing framework to use (jasmine/mocha/qunit/...)
9+
frameworks: ['mocha', 'chai', 'chai-things', 'chai-as-promised'],
10+
11+
// list of files / patterns to load in the browser
12+
files: [
13+
'bower_components/angular/angular.js',
14+
'node_modules/angular-mocks/angular-mocks.js',
15+
'src/*.js',
16+
'tests/spec/*.js',
17+
'src/*.html'
18+
],
19+
20+
// list of files / patterns to exclude
21+
exclude: [],
22+
23+
// preprocess matching files before serving them to the browser
24+
preprocessors: {
25+
"src/*Tpl.html": 'ng-html2js'
26+
},
27+
28+
ngHtml2JsPreprocessor: {
29+
stripPrefix: 'src/',
30+
moduleName: 'appTemplates'
31+
},
32+
33+
// web server port
34+
port: 9998,
35+
36+
// level of logging
37+
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
38+
logLevel: config.LOG_INFO,
39+
40+
41+
// enable / disable watching file and executing tests whenever any file changes
42+
autoWatch: false,
43+
44+
45+
// Start these browsers, currently available:
46+
// - Chrome
47+
// - ChromeCanary
48+
// - Firefox
49+
// - Opera
50+
// - Safari (only Mac)
51+
// - PhantomJS
52+
// - IE (only Windows)
53+
browsers: ['PhantomJS'],
54+
55+
// Continuous Integration mode
56+
// if true, it capture browsers, run tests and exit
57+
singleRun: false
58+
})
59+
;
60+
}
61+
;

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,28 @@
1212
"slider"
1313
],
1414
"devDependencies": {
15+
"angular-mocks": "^1.4.8",
16+
"chai": "^3.4.1",
17+
"chai-as-promised": "^5.1.0",
18+
"chai-things": "^0.2.0",
1519
"grunt": "~0.4.2",
1620
"grunt-angular-templates": "^0.5.7",
1721
"grunt-contrib-mincss": "~0.3.2",
1822
"grunt-contrib-uglify": "~0.2.2",
23+
"grunt-contrib-watch": "^0.6.1",
24+
"grunt-karma": "^0.12.1",
1925
"grunt-ng-annotate": "^1.0.1",
2026
"grunt-recess": "~0.4.0",
2127
"grunt-replace": "^0.11.0",
22-
"grunt-contrib-watch": "^0.6.1",
2328
"grunt-serve": "^0.1.6",
29+
"karma": "^0.13.15",
30+
"karma-chai-plugins": "^0.6.1",
31+
"karma-chrome-launcher": "^0.2.2",
32+
"karma-mocha": "^0.2.1",
33+
"karma-ng-html2js-preprocessor": "^0.2.0",
34+
"karma-phantomjs-launcher": "^0.2.1",
35+
"mocha": "^2.3.4",
36+
"phantomjs": "^1.9.19",
2437
"recess": "~1.1.9"
2538
},
2639
"author": "Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]>",

tests/spec/rz-slider-service-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
describe('rzslider api', function () {
4+
var RzSlider;
5+
var $rootScope;
6+
var scope;
7+
var $compile;
8+
var element;
9+
var $httpBackend;
10+
beforeEach(module('rzModule'));
11+
beforeEach(module('appTemplates'));
12+
13+
beforeEach(inject(function (_RzSlider_, _$rootScope_, _$compile_, _$httpBackend_) {
14+
RzSlider = _RzSlider_;
15+
$rootScope = _$rootScope_;
16+
$compile = _$compile_;
17+
$httpBackend = _$httpBackend_;
18+
}));
19+
20+
it('should exist compiled', function () {
21+
scope = $rootScope.$new();
22+
scope.minSlider = {
23+
value: 10
24+
};
25+
element = $compile("<rzslider rz-slider-model='minSlider.value'></rzslider>")($rootScope);
26+
$rootScope.$digest();
27+
expect(element.find('span')).to.have.length(11);
28+
});
29+
30+
});

0 commit comments

Comments
 (0)