Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 859b1e3

Browse files
committed
test(jQuery): Run tests with jQuery 3
Closes #14874
1 parent 489224b commit 859b1e3

8 files changed

+67
-43
lines changed

Gruntfile.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ module.exports = function(grunt) {
8383
tests: {
8484
jqlite: 'karma-jqlite.conf.js',
8585
jquery: 'karma-jquery.conf.js',
86+
'jquery-2.2': 'karma-jquery-2.2.conf.js',
8687
'jquery-2.1': 'karma-jquery-2.1.conf.js',
8788
docs: 'karma-docs.conf.js',
8889
modules: 'karma-modules.conf.js'
@@ -92,6 +93,7 @@ module.exports = function(grunt) {
9293
autotest: {
9394
jqlite: 'karma-jqlite.conf.js',
9495
jquery: 'karma-jquery.conf.js',
96+
'jquery-2.2': 'karma-jquery-2.2.conf.js',
9597
'jquery-2.1': 'karma-jquery-2.1.conf.js',
9698
modules: 'karma-modules.conf.js',
9799
docs: 'karma-docs.conf.js'
@@ -364,10 +366,11 @@ module.exports = function(grunt) {
364366
grunt.registerTask('test', 'Run unit, docs and e2e tests with Karma', ['jshint', 'jscs', 'package', 'test:unit', 'test:promises-aplus', 'tests:docs', 'test:protractor']);
365367
grunt.registerTask('test:jqlite', 'Run the unit tests with Karma' , ['tests:jqlite']);
366368
grunt.registerTask('test:jquery', 'Run the jQuery (latest) unit tests with Karma', ['tests:jquery']);
369+
grunt.registerTask('test:jquery-2.2', 'Run the jQuery 2.2 unit tests with Karma', ['tests:jquery-2.2']);
367370
grunt.registerTask('test:jquery-2.1', 'Run the jQuery 2.1 unit tests with Karma', ['tests:jquery-2.1']);
368371
grunt.registerTask('test:modules', 'Run the Karma module tests with Karma', ['build', 'tests:modules']);
369372
grunt.registerTask('test:docs', 'Run the doc-page tests with Karma', ['package', 'tests:docs']);
370-
grunt.registerTask('test:unit', 'Run unit, jQuery and Karma module tests with Karma', ['test:jqlite', 'test:jquery', 'test:jquery-2.1', 'test:modules']);
373+
grunt.registerTask('test:unit', 'Run unit, jQuery and Karma module tests with Karma', ['test:jqlite', 'test:jquery', 'test:jquery-2.2', 'test:jquery-2.1', 'test:modules']);
371374
grunt.registerTask('test:protractor', 'Run the end to end tests with Protractor and keep a test server running in the background', ['webdriver', 'connect:testserver', 'protractor:normal']);
372375
grunt.registerTask('test:travis-protractor', 'Run the end to end tests with Protractor for Travis CI builds', ['connect:testserver', 'protractor:travis']);
373376
grunt.registerTask('test:ci-protractor', 'Run the end to end tests with Protractor for Jenkins CI builds', ['webdriver', 'connect:testserver', 'protractor:jenkins']);

angularFiles.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,6 @@ var angularFiles = {
236236
'@angularTest'
237237
],
238238

239-
'karmaJqueryOld': [
240-
'bower_components/jquery-2.1/dist/jquery.js',
241-
'test/jquery_alias.js',
242-
'@angularSrc',
243-
'@angularSrcModules',
244-
'@angularScenario',
245-
'@angularTest'
246-
],
247-
248239
'karmaJqueryExclude': [
249240
'src/angular-bootstrap.js',
250241
'src/ngScenario/angular-bootstrap.js',
@@ -253,6 +244,17 @@ var angularFiles = {
253244
]
254245
};
255246

247+
['2.1', '2.2'].forEach(function (jQueryVersion) {
248+
angularFiles['karmaJquery' + jQueryVersion] = []
249+
.concat(angularFiles.karmaJquery)
250+
.map(function (path) {
251+
if (path.startsWith('bower_components/jquery')) {
252+
return path.replace(/^bower_components\/jquery/, 'bower_components/jquery-' + jQueryVersion);
253+
}
254+
return path;
255+
});
256+
});
257+
256258
angularFiles['angularSrcModules'] = [].concat(
257259
angularFiles['angularModules']['ngAnimate'],
258260
angularFiles['angularModules']['ngMessageFormat'],

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "AngularJS",
33
"license": "MIT",
44
"devDependencies": {
5-
"jquery": "2.2.3",
5+
"jquery": "3.1.0",
6+
"jquery-2.2": "jquery#2.2.4",
67
"jquery-2.1": "jquery#2.1.4",
78
"closure-compiler": "https://dl.google.com/closure-compiler/compiler-20140814.zip",
89
"ng-closure-runner": "https://raw.github.com/angular/ng-closure-runner/v0.2.3/assets/ng-closure-runner.zip"

karma-jquery-2.1.conf.js

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
'use strict';
22

3-
var angularFiles = require('./angularFiles');
4-
var sharedConfig = require('./karma-shared.conf');
3+
var karmaConfigFactory = require('./karma-jquery.conf-factory');
54

6-
module.exports = function(config) {
7-
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});
8-
9-
config.set({
10-
files: angularFiles.mergeFilesFor('karmaJqueryOld'),
11-
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),
12-
13-
junitReporter: {
14-
outputFile: 'test_out/jquery.xml',
15-
suite: 'jQuery'
16-
}
17-
});
18-
};
5+
module.exports = karmaConfigFactory('2.1');

karma-jquery-2.2.conf.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
var karmaConfigFactory = require('./karma-jquery.conf-factory');
4+
5+
module.exports = karmaConfigFactory('2.2');

karma-jquery.conf-factory.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
var angularFiles = require('./angularFiles');
4+
var sharedConfig = require('./karma-shared.conf');
5+
6+
module.exports = function (version) {
7+
version = version || '';
8+
9+
return function(config) {
10+
sharedConfig(config, {
11+
testName: 'AngularJS: jQuery' + (version ? ' ' + version : ''),
12+
logFile: 'karma-jquery' + version + '.log'
13+
});
14+
15+
config.set({
16+
files: angularFiles.mergeFilesFor('karmaJquery' + version),
17+
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),
18+
19+
junitReporter: {
20+
outputFile: 'test_out/jquery.xml',
21+
suite: 'jQuery'
22+
}
23+
});
24+
};
25+
};

karma-jquery.conf.js

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
'use strict';
22

3-
var angularFiles = require('./angularFiles');
4-
var sharedConfig = require('./karma-shared.conf');
3+
var karmaConfigFactory = require('./karma-jquery.conf-factory');
54

6-
module.exports = function(config) {
7-
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});
8-
9-
config.set({
10-
files: angularFiles.mergeFilesFor('karmaJquery'),
11-
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),
12-
13-
junitReporter: {
14-
outputFile: 'test_out/jquery.xml',
15-
suite: 'jQuery'
16-
}
17-
});
18-
};
5+
module.exports = karmaConfigFactory();

test/ng/directive/selectSpec.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,14 @@ describe('select', function() {
19121912
optionElements = element.find('option');
19131913
expect(optionElements.length).toEqual(1);
19141914
expect(scope.obj.value).toEqual([]);
1915-
expect(element.val()).toBe(null);
1915+
1916+
// Cover both jQuery 3.x ([]) and 2.x (null) behavior.
1917+
var val = element.val();
1918+
if (val === null) {
1919+
val = [];
1920+
}
1921+
expect(val).toEqual([]);
1922+
19161923
expect(ngModelCtrlSpy).toHaveBeenCalledTimes(1);
19171924
});
19181925

@@ -1970,7 +1977,14 @@ describe('select', function() {
19701977
optionElements = element.find('option');
19711978
expect(optionElements.length).toEqual(3);
19721979
expect(scope.obj.value).toEqual([]);
1973-
expect(element.val()).toBe(null);
1980+
1981+
// Cover both jQuery 3.x ([]) and 2.x (null) behavior.
1982+
var val = element.val();
1983+
if (val === null) {
1984+
val = [];
1985+
}
1986+
expect(val).toEqual([]);
1987+
19741988
expect(ngModelCtrlSpy).toHaveBeenCalledTimes(1);
19751989

19761990
});

0 commit comments

Comments
 (0)