Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 7b61253

Browse files
committed
feat(sortable): log error if jquery was not available to angular on load
1 parent 664e7de commit 7b61253

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/sortable.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ angular.module('ui.sortable', [])
3535

3636
angular.extend(opts, uiSortableConfig);
3737

38+
if (!angular.element.fn || !angular.element.fn.jquery) {
39+
$log.error('ui.sortable: jQuery should be included before AngularJS!');
40+
return;
41+
}
42+
3843
if (ngModel) {
3944

4045
// When we add or remove elements, we need the sortable to 'refresh'

test/sortable.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ describe('uiSortable', function() {
3636
});
3737
});
3838

39+
it('should log an error about jQuery dependency', function() {
40+
inject(function($compile, $rootScope, $log) {
41+
var oldAngularElementFn = angular.element.fn;
42+
var mockJQliteFn = $({}, angular.element.fn, true);
43+
mockJQliteFn.jquery = null;
44+
angular.element.fn = mockJQliteFn;
45+
46+
this.after(function () {
47+
angular.element.fn = oldAngularElementFn;
48+
});
49+
50+
var element;
51+
element = $compile('<ul ui-sortable><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
52+
$rootScope.$apply(function() {
53+
$rootScope.items = ['One', 'Two', 'Three'];
54+
});
55+
56+
expect($log.error.logs.length).toEqual(1);
57+
expect($log.error.logs[0].length).toEqual(1);
58+
expect($log.error.logs[0][0]).toEqual('ui.sortable: jQuery should be included before AngularJS!');
59+
});
60+
});
61+
3962
it('should refresh sortable properly after an apply', function() {
4063
inject(function($compile, $rootScope, $timeout) {
4164
var element;

0 commit comments

Comments
 (0)