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

test(jQuery): Run tests with jQuery 3 #14874

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = function(grunt) {
tests: {
jqlite: 'karma-jqlite.conf.js',
jquery: 'karma-jquery.conf.js',
'jquery-2.2': 'karma-jquery-2.2.conf.js',
'jquery-2.1': 'karma-jquery-2.1.conf.js',
docs: 'karma-docs.conf.js',
modules: 'karma-modules.conf.js'
Expand All @@ -92,6 +93,7 @@ module.exports = function(grunt) {
autotest: {
jqlite: 'karma-jqlite.conf.js',
jquery: 'karma-jquery.conf.js',
'jquery-2.2': 'karma-jquery-2.2.conf.js',
'jquery-2.1': 'karma-jquery-2.1.conf.js',
modules: 'karma-modules.conf.js',
docs: 'karma-docs.conf.js'
Expand Down Expand Up @@ -364,10 +366,11 @@ module.exports = function(grunt) {
grunt.registerTask('test', 'Run unit, docs and e2e tests with Karma', ['jshint', 'jscs', 'package', 'test:unit', 'test:promises-aplus', 'tests:docs', 'test:protractor']);
grunt.registerTask('test:jqlite', 'Run the unit tests with Karma' , ['tests:jqlite']);
grunt.registerTask('test:jquery', 'Run the jQuery (latest) unit tests with Karma', ['tests:jquery']);
grunt.registerTask('test:jquery-2.2', 'Run the jQuery 2.2 unit tests with Karma', ['tests:jquery-2.2']);
grunt.registerTask('test:jquery-2.1', 'Run the jQuery 2.1 unit tests with Karma', ['tests:jquery-2.1']);
grunt.registerTask('test:modules', 'Run the Karma module tests with Karma', ['build', 'tests:modules']);
grunt.registerTask('test:docs', 'Run the doc-page tests with Karma', ['package', 'tests:docs']);
grunt.registerTask('test:unit', 'Run unit, jQuery and Karma module tests with Karma', ['test:jqlite', 'test:jquery', 'test:jquery-2.1', 'test:modules']);
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']);
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']);
grunt.registerTask('test:travis-protractor', 'Run the end to end tests with Protractor for Travis CI builds', ['connect:testserver', 'protractor:travis']);
grunt.registerTask('test:ci-protractor', 'Run the end to end tests with Protractor for Jenkins CI builds', ['webdriver', 'connect:testserver', 'protractor:jenkins']);
Expand Down
20 changes: 11 additions & 9 deletions angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,6 @@ var angularFiles = {
'@angularTest'
],

'karmaJqueryOld': [
'bower_components/jquery-2.1/dist/jquery.js',
'test/jquery_alias.js',
'@angularSrc',
'@angularSrcModules',
'@angularScenario',
'@angularTest'
],

'karmaJqueryExclude': [
'src/angular-bootstrap.js',
'src/ngScenario/angular-bootstrap.js',
Expand All @@ -253,6 +244,17 @@ var angularFiles = {
]
};

['2.1', '2.2'].forEach(function (jQueryVersion) {
angularFiles['karmaJquery' + jQueryVersion] = []
.concat(angularFiles.karmaJquery)
.map(function (path) {
if (path.startsWith('bower_components/jquery')) {
return path.replace(/^bower_components\/jquery/, 'bower_components/jquery-' + jQueryVersion);
}
return path;
});
});

angularFiles['angularSrcModules'] = [].concat(
angularFiles['angularModules']['ngAnimate'],
angularFiles['angularModules']['ngMessageFormat'],
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "AngularJS",
"license": "MIT",
"devDependencies": {
"jquery": "2.2.3",
"jquery": "3.1.0",
"jquery-2.2": "jquery#2.2.4",
"jquery-2.1": "jquery#2.1.4",
"closure-compiler": "https://dl.google.com/closure-compiler/compiler-20140814.zip",
"ng-closure-runner": "https://raw.github.com/angular/ng-closure-runner/v0.2.3/assets/ng-closure-runner.zip"
Expand Down
17 changes: 2 additions & 15 deletions karma-jquery-2.1.conf.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
'use strict';

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

module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});

config.set({
files: angularFiles.mergeFilesFor('karmaJqueryOld'),
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),

junitReporter: {
outputFile: 'test_out/jquery.xml',
suite: 'jQuery'
}
});
};
module.exports = karmaConfigFactory('2.1');
5 changes: 5 additions & 0 deletions karma-jquery-2.2.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var karmaConfigFactory = require('./karma-jquery.conf-factory');

module.exports = karmaConfigFactory('2.2');
25 changes: 25 additions & 0 deletions karma-jquery.conf-factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var angularFiles = require('./angularFiles');
var sharedConfig = require('./karma-shared.conf');

module.exports = function (version) {
version = version || '';

return function(config) {
sharedConfig(config, {
testName: 'AngularJS: jQuery' + (version ? ' ' + version : ''),
logFile: 'karma-jquery' + version + '.log'
});

config.set({
files: angularFiles.mergeFilesFor('karmaJquery' + version),
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),

junitReporter: {
outputFile: 'test_out/jquery.xml',
suite: 'jQuery'
}
});
};
};
17 changes: 2 additions & 15 deletions karma-jquery.conf.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
'use strict';

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

module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});

config.set({
files: angularFiles.mergeFilesFor('karmaJquery'),
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),

junitReporter: {
outputFile: 'test_out/jquery.xml',
suite: 'jQuery'
}
});
};
module.exports = karmaConfigFactory();
18 changes: 16 additions & 2 deletions test/ng/directive/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,14 @@ describe('select', function() {
optionElements = element.find('option');
expect(optionElements.length).toEqual(1);
expect(scope.obj.value).toEqual([]);
expect(element.val()).toBe(null);

// Cover both jQuery 3.x ([]) and 2.x (null) behavior.
var val = element.val();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about toEqual(null || [])? Does that work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toEqual(null || []) is the same as toEqual([]). :-) The expression will be computed before passing it to toEqual.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have custom toBeOneOf() matcher. If we only had toEqualOneOf() 😛

if (val === null) {
val = [];
}
expect(val).toEqual([]);

expect(ngModelCtrlSpy).toHaveBeenCalledTimes(1);
});

Expand Down Expand Up @@ -1970,7 +1977,14 @@ describe('select', function() {
optionElements = element.find('option');
expect(optionElements.length).toEqual(3);
expect(scope.obj.value).toEqual([]);
expect(element.val()).toBe(null);

// Cover both jQuery 3.x ([]) and 2.x (null) behavior.
var val = element.val();
if (val === null) {
val = [];
}
expect(val).toEqual([]);

expect(ngModelCtrlSpy).toHaveBeenCalledTimes(1);

});
Expand Down