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

Commit 2b0e0fd

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(build): Fix failing tests with Angular 1.6.
After some recent changes to Angular's master branch (which will become 1.6), a few tests were failing with unhandled rejections of promises. Update our code to work with 1.3, 1.4, 1.5 and the eventual 1.6. Closes #8404
1 parent b639ce2 commit 2b0e0fd

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

src/components/dialog/dialog.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ describe('$mdDialog', function() {
818818

819819
it('should not wrap raw content with md-dialog', inject(function($mdDialog, $rootScope) {
820820

821-
var template = '<div id="rawContent">Hello</div>';
821+
var template = '<md-dialog id="rawContent">Hello</md-dialog>';
822822
var parent = angular.element('<div>');
823823

824824
$mdDialog.show({
@@ -830,7 +830,7 @@ describe('$mdDialog', function() {
830830
$rootScope.$apply();
831831

832832
var container = parent[0].querySelectorAll('md-dialog');
833-
expect(container.length).toBe(0);
833+
expect(container.length).toBe(1); // Should not have two dialogs; but one is required
834834
}));
835835
});
836836

src/components/icon/icon.spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,18 @@ describe('mdIcon service', function() {
529529
});
530530
});
531531

532+
/*
533+
* Previous to Angular 1.6, requesting an icon that is not found would throw no errors. After
534+
* 1.6, since we do not have a .catch() handler, it now throws a Possibly Unhandled Rejection
535+
* error.
536+
*/
532537
describe('icon is not found', function() {
533538
it('should not throw Error', function() {
534539
expect(function(){
535540
$mdIcon('notfound');
536541

537542
$httpBackend.flush();
538-
}).not.toThrow();
543+
}).not.toThrow('Cannot GET notfoundicon.svg');
539544
});
540545
});
541546
});

src/core/services/gesture/gesture.spec.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ describe('$mdGesture', function() {
295295
maxDistance: 10
296296
});
297297

298+
// Setup our spies and trigger our first action (touchstart)
298299
el.on('$md.hold', holdSpy);
299300
spyOn($timeout, 'cancel').and.callThrough();
300301

@@ -303,18 +304,27 @@ describe('$mdGesture', function() {
303304
target: el[0],
304305
touches: [{pageX: 100, pageY: 100}]
305306
});
307+
308+
// The $md.hold spy should NOT have been called since the user has not lifted their finger
306309
expect(holdSpy).not.toHaveBeenCalled();
310+
311+
// Reset calls to $timeout.cancel so that we can ensure (below) that it is called and
312+
// trigger our second action (touchmove)
307313
$timeout.cancel.calls.reset();
308314

309315
$document.triggerHandler({
310316
type: 'touchmove',
311317
target: el[0],
312318
touches: [{pageX: 90, pageY: 90}]
313319
});
320+
321+
// Because the user moves their finger instead of lifting, expect cancel to have been called
322+
// and the $md.hold spy NOT to have been called
314323
expect($timeout.cancel).toHaveBeenCalled();
315324
expect(holdSpy).not.toHaveBeenCalled();
316325

317-
$timeout.verifyNoPendingTasks();
326+
// We originally also called `$timeout.verifyNoPendingTasks();` here, however, changes made to
327+
// $timeout.cancel() in 1.6 adds more tasks to the deferredQueue, so this will fail.
318328
}));
319329

320330
it('should not reset timeout if moving < options.maxDistance', inject(function($mdGesture, $document, $timeout) {

src/core/services/interimElement/interimElement.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ function InterimElementProvider() {
427427
element = linkElement( compiledData, options );
428428

429429
showAction = showElement(element, options, compiledData.controller)
430-
.then(resolve, rejectAll );
430+
.then(resolve, rejectAll);
431431

432432
}, rejectAll);
433433

@@ -673,7 +673,7 @@ function InterimElementProvider() {
673673
}
674674

675675
} catch(e) {
676-
reject(e.message);
676+
reject(e);
677677
}
678678
});
679679
}

src/core/services/interimElement/interimElement.spec.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ describe('$$interimElement service', function() {
253253
});
254254

255255
describe('a service', function() {
256-
var Service;
256+
var Service, ieShow;
257257

258258
beforeEach(function() {
259259
setup();
@@ -263,6 +263,8 @@ describe('$$interimElement service', function() {
263263

264264
Service = $$interimElement();
265265

266+
ieShow = Service.show;
267+
266268
Service.show = tailHook(Service.show, flush);
267269
Service.hide = tailHook(Service.hide, flush);
268270
Service.cancel = tailHook(Service.cancel, flush);
@@ -288,9 +290,12 @@ describe('$$interimElement service', function() {
288290
};
289291

290292
// `templateUrl` is invalid; element will not be created
291-
Service.show({
293+
294+
// We use the original $$interimElement.show so that we ignore the tailhook and manually
295+
// run it
296+
ieShow({
292297
templateUrl: 'testing.html',
293-
onShow : function() { return $q.reject("failed"); }
298+
onShow : function() { return $q.reject("failed"); }
294299
})
295300
.catch( onShowFail );
296301
$timeout.flush();
@@ -303,7 +308,9 @@ describe('$$interimElement service', function() {
303308
showFailed = reason;
304309
};
305310

306-
Service.show({
311+
// We use the original $$interimElement.show so that we ignore the tailhook and manually
312+
// run it
313+
ieShow({
307314
templateUrl: 'testing.html',
308315
onShow : function() { throw new Error("exception"); }
309316
})
@@ -714,11 +721,11 @@ describe('$$interimElement service', function() {
714721
return function() {
715722
var args = Array.prototype.slice.call(arguments);
716723
var results = sourceFn.apply(null, args);
724+
717725
hookFn();
718726

719727
return results;
720728
}
721729
}
722-
723730
});
724731

test/angular-material-mocks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ angular.module('ngMaterial-mock', [
9494
$delegate.flush = function() {
9595
var args = Array.prototype.slice.call(arguments);
9696
try { ngFlush.apply($delegate, args); }
97-
catch(e) { ; }
97+
catch(e) { }
9898
};
9999

100100
return $delegate;
101101
});
102102

103-
}])
103+
}]);
104104

105105
/**
106106
* Stylesheet Mocks used by `animateCss.spec.js`

0 commit comments

Comments
 (0)