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

feat(sortable): log error if jquery was not available to angular on load #165

Merged
merged 2 commits into from
Apr 27, 2014
Merged
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
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-ui-sortable",
"version": "0.12.4",
"version": "0.12.5",
"description": "This directive allows you to jQueryUI Sortable.",
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-ui-sortable",
"version": "0.12.4",
"version": "0.12.5",
"description": "This directive allows you to jQueryUI Sortable.",
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
"license": "MIT",
Expand Down
5 changes: 5 additions & 0 deletions src/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ angular.module('ui.sortable', [])

angular.extend(opts, uiSortableConfig);

if (!angular.element.fn || !angular.element.fn.jquery) {
$log.error('ui.sortable: jQuery should be included before AngularJS!');
return;
}

if (ngModel) {

// When we add or remove elements, we need the sortable to 'refresh'
Expand Down
23 changes: 23 additions & 0 deletions test/sortable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ describe('uiSortable', function() {
});
});

it('should log an error about jQuery dependency', function() {
inject(function($compile, $rootScope, $log) {
var oldAngularElementFn = angular.element.fn;
var mockJQliteFn = $({}, angular.element.fn, true);
mockJQliteFn.jquery = null;
angular.element.fn = mockJQliteFn;

this.after(function () {
angular.element.fn = oldAngularElementFn;
});

var element;
element = $compile('<ul ui-sortable><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
$rootScope.$apply(function() {
$rootScope.items = ['One', 'Two', 'Three'];
});

expect($log.error.logs.length).toEqual(1);
expect($log.error.logs[0].length).toEqual(1);
expect($log.error.logs[0][0]).toEqual('ui.sortable: jQuery should be included before AngularJS!');
});
});

it('should refresh sortable properly after an apply', function() {
inject(function($compile, $rootScope, $timeout) {
var element;
Expand Down