Skip to content

Commit

Permalink
add tests specific for angular 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
chieffancypants committed Feb 19, 2016
1 parent 542b42d commit ad2b482
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 12 deletions.
10 changes: 9 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ module.exports = function(grunt) {
dir: 'coverage/'
}
},
unit14: {
configFile: 'test/karma-angular-1.4.conf.js',
singleRun: true,
coverageReporter: {
type: 'text',
dir: 'coverage/'
}
},
watch: {
configFile: 'test/karma-angular-1.2.conf.js',
singleRun: false,
Expand Down Expand Up @@ -87,7 +95,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-karma');

grunt.registerTask('default', ['jshint', 'karma:unit', 'karma:unit13', 'uglify', 'cssmin', 'concat:build']);
grunt.registerTask('default', ['jshint', 'karma:unit', 'karma:unit13', 'karma:unit14', 'uglify', 'cssmin', 'concat:build']);
grunt.registerTask('test', ['karma:watch']);
grunt.registerTask('build', ['default']);

Expand Down
5 changes: 4 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
"devDependencies": {
"angular": "~1.2.23",
"angular-1.3": "angular#1.3",
"angular-1.4": "angular#1.4",
"angular-mocks": "~1.2.9",
"angular-mocks-1.3": "angular-mocks#1.3",
"angular-mocks-1.4": "angular-mocks#1.4",
"angular-animate": "~1.2.9",
"angular-animate-1.3": "angular-animate#1.3"
"angular-animate-1.3": "angular-animate#1.3",
"angular-animate-1.4": "angular-animate#1.4"
},
"resolutions": {
"angular": "~1.2.23"
Expand Down
4 changes: 2 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head>
<!-- angular -->
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-animate.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<!-- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-animate.min.js"></script> -->

<!-- loadingbar -->
<script src="../src/loading-bar.js"></script>
Expand Down
82 changes: 82 additions & 0 deletions test/karma-angular-1.4.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Karma configuration
// Generated on Sun Sep 15 2013 20:18:09 GMT-0400 (EDT)

module.exports = function(config) {
config.set({

// base path, that will be used to resolve files and exclude
basePath: '',


// frameworks to use
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
'../bower_components/angular-1.4/angular.js',
'../bower_components/angular-animate-1.4/angular-animate.js',
'../bower_components/angular-mocks-1.4/angular-mocks.js',
'../src/*.js',
'*.coffee'
],


// list of files to exclude
exclude: [

],


// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress', 'coverage'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],

coverageReporter: {
type : 'html',
dir : 'coverage/',
},

preprocessors: {
'../src/*.js': ['coverage'],
'*.coffee': 'coffee'
},


// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
22 changes: 14 additions & 8 deletions test/loading-bar-interceptor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ isLoadingBarInjected = (doc) ->
break
return injected

flush = null

describe 'loadingBarInterceptor Service', ->

$http = $httpBackend = $document = $timeout = result = loadingBar = $animate = null
Expand All @@ -26,6 +28,11 @@ describe 'loadingBarInterceptor Service', ->
$timeout = _$timeout_
$animate = _$animate_

# Angular 1.4 removed triggerCalbacks(), so try them both:
flush = () ->
$animate.flush && $animate.flush()
$animate.triggerCallbacks && $animate.triggerCallbacks()

beforeEach ->
this.addMatchers
toBeBetween: (high, low) ->
Expand Down Expand Up @@ -54,7 +61,7 @@ describe 'loadingBarInterceptor Service', ->
expect(cfpLoadingBar.status()).toBe 1
cfpLoadingBar.complete() # set as complete
$timeout.flush()
$animate.triggerCallbacks()
flush()


$http.get(endpoint, cache: cache).then (data) ->
Expand All @@ -77,7 +84,7 @@ describe 'loadingBarInterceptor Service', ->
expect(cfpLoadingBar.status()).toBe 1
cfpLoadingBar.complete() # set as complete
$timeout.flush()
$animate.triggerCallbacks()
flush()


$http.get(endpoint).then (data) ->
Expand All @@ -99,7 +106,7 @@ describe 'loadingBarInterceptor Service', ->
expect(cfpLoadingBar.status()).toBe 1
cfpLoadingBar.complete() # set as complete
$timeout.flush()
$animate.triggerCallbacks()
flush()


$http.get(endpoint, cache: true).then (data) ->
Expand All @@ -123,7 +130,7 @@ describe 'loadingBarInterceptor Service', ->
expect(cfpLoadingBar.status()).toBe 1
cfpLoadingBar.complete() # set as complete
$timeout.flush()
$animate.triggerCallbacks()
flush()


$http.get(endpoint).then (data) ->
Expand All @@ -144,7 +151,7 @@ describe 'loadingBarInterceptor Service', ->
$httpBackend.flush(1)
expect(cfpLoadingBar.status()).toBe 1
$timeout.flush()
$animate.triggerCallbacks()
flush()


$httpBackend.expectPOST(endpoint).respond response
Expand Down Expand Up @@ -383,7 +390,7 @@ describe 'loadingBarInterceptor Service', ->
expect(startedEventCalled).toBe 1 # Should still be one, as complete was never called:
cfpLoadingBar.complete()
$timeout.flush()
$animate.triggerCallbacks()
flush()


cfpLoadingBar.start()
Expand Down Expand Up @@ -478,13 +485,12 @@ describe 'LoadingBar only', ->
cfpLoadingBar.complete()
cfpLoadingBar.start()
$timeout.flush()
$animate.triggerCallbacks()

expect(isLoadingBarInjected($document.find(cfpLoadingBar.parentSelector))).toBe true

cfpLoadingBar.complete()
$timeout.flush()
$animate.triggerCallbacks()
flush()

expect(isLoadingBarInjected($document.find(cfpLoadingBar.parentSelector))).toBe false

Expand Down

0 comments on commit ad2b482

Please sign in to comment.