-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(build): Fix failing tests with Angular 1.6. #8404
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -529,13 +529,18 @@ describe('mdIcon service', function() { | |
}); | ||
}); | ||
|
||
/* | ||
* Previous to Angular 1.6, requesting an icon that is not found would throw no errors. After | ||
* 1.6, since we do not have a .catch() handler, it now throws a Possibly Unhandled Rejection | ||
* error. | ||
*/ | ||
describe('icon is not found', function() { | ||
it('should not throw Error', function() { | ||
expect(function(){ | ||
$mdIcon('notfound'); | ||
|
||
$httpBackend.flush(); | ||
}).not.toThrow(); | ||
}).not.toThrow('Cannot GET notfoundicon.svg'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is quite brittle (e.g. it coould be throwing a different error or there might be a typo in the error message). TBH, I'm not sure what this test verifies and what the expected behavior is or why would it throw. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We went back and forth on this single test for almost an hour. The issue is that if we I agree that it is a bit brittle if the error description changes, but I think I would want this test to fail if the error changes so that we know. I'm slightly worried that if something else throws an error (besides the PUR in 1.6) that it will get swallowed, but we have a lot of other tests that should catch that too. We honestly talked about just removing the test, but I think it's better to have it than to not. I think all this test is really trying to say is "if we can't find the icon, we shouldn't throw an icon not found error", and that's all we really want to guarantee. I'm always open to thoughts on how to fix it if you have a moment to dive in and try some code 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean if you are verifying that I am confused because I am not sure if you want to verify that it doesn't throw an error or that the promise isn't rejected. The way I'm thinking it, I would rather chain a |
||
}); | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,6 +295,7 @@ describe('$mdGesture', function() { | |
maxDistance: 10 | ||
}); | ||
|
||
// Setup our spies and trigger our first action (touchstart) | ||
el.on('$md.hold', holdSpy); | ||
spyOn($timeout, 'cancel').and.callThrough(); | ||
|
||
|
@@ -303,18 +304,27 @@ describe('$mdGesture', function() { | |
target: el[0], | ||
touches: [{pageX: 100, pageY: 100}] | ||
}); | ||
|
||
// The $md.hold spy should NOT have been called since the user has not lifted their finger | ||
expect(holdSpy).not.toHaveBeenCalled(); | ||
|
||
// Reset calls to $timeout.cancel so that we can ensure (below) that it is called and | ||
// trigger our second action (touchmove) | ||
$timeout.cancel.calls.reset(); | ||
|
||
$document.triggerHandler({ | ||
type: 'touchmove', | ||
target: el[0], | ||
touches: [{pageX: 90, pageY: 90}] | ||
}); | ||
|
||
// Because the user moves their finger instead of lifting, expect cancel to have been called | ||
// and the $md.hold spy NOT to have been called | ||
expect($timeout.cancel).toHaveBeenCalled(); | ||
expect(holdSpy).not.toHaveBeenCalled(); | ||
|
||
$timeout.verifyNoPendingTasks(); | ||
// We originally also called `$timeout.verifyNoPendingTasks();` here, however, changes made to | ||
// $timeout.cancel() in 1.6 adds more tasks to the deferredQueue, so this will fail. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, this is an issue with Angular and will be fixed soon-ish (see angular/angular.js#14336). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gkalpak Good to know! I'll follow that one. |
||
})); | ||
|
||
it('should not reset timeout if moving < options.maxDistance', inject(function($mdGesture, $document, $timeout) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,7 +253,7 @@ describe('$$interimElement service', function() { | |
}); | ||
|
||
describe('a service', function() { | ||
var Service; | ||
var Service, ieShow; | ||
|
||
beforeEach(function() { | ||
setup(); | ||
|
@@ -263,6 +263,8 @@ describe('$$interimElement service', function() { | |
|
||
Service = $$interimElement(); | ||
|
||
ieShow = Service.show; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, I think it's not a good idea to mock services methods in tests only for convenience, as it might hide actual issues (or make breakages hard to debug). I would create helper functions instead (e.g. When tinkering with this locally, I used the following helpers: function callMethodAndFlush(method, args) {
var result = Service[method].apply(Service, args);
$material.flushInterimElement();
return result;
}
function cancelAndFlush() {
return callMethodAndFlush('cancel', arguments);
}
function hideAndFlush() {
return callMethodAndFlush('hide', arguments);
}
function showAndFlush() {
return callMethodAndFlush('show', arguments);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, we may want to refactor it and use something like this; and I'll definitely do this in future tests. |
||
|
||
Service.show = tailHook(Service.show, flush); | ||
Service.hide = tailHook(Service.hide, flush); | ||
Service.cancel = tailHook(Service.cancel, flush); | ||
|
@@ -288,9 +290,12 @@ describe('$$interimElement service', function() { | |
}; | ||
|
||
// `templateUrl` is invalid; element will not be created | ||
Service.show({ | ||
|
||
// We use the original $$interimElement.show so that we ignore the tailhook and manually | ||
// run it | ||
ieShow({ | ||
templateUrl: 'testing.html', | ||
onShow : function() { return $q.reject("failed"); } | ||
onShow : function() { return $q.reject("failed"); } | ||
}) | ||
.catch( onShowFail ); | ||
$timeout.flush(); | ||
|
@@ -303,7 +308,9 @@ describe('$$interimElement service', function() { | |
showFailed = reason; | ||
}; | ||
|
||
Service.show({ | ||
// We use the original $$interimElement.show so that we ignore the tailhook and manually | ||
// run it | ||
ieShow({ | ||
templateUrl: 'testing.html', | ||
onShow : function() { throw new Error("exception"); } | ||
}) | ||
|
@@ -714,11 +721,11 @@ describe('$$interimElement service', function() { | |
return function() { | ||
var args = Array.prototype.slice.call(arguments); | ||
var results = sourceFn.apply(null, args); | ||
|
||
hookFn(); | ||
|
||
return results; | ||
} | ||
} | ||
|
||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are testing raw content, this should be a
<div>
right ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test tests essentialy the same thing as the "should not wrap content with existing md-dialog" one (two tests above). If raw content should always manually include
<md-dialog>
then it should be more explicit imo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThomasBurleson With a
<div>
, the test fails because it's trying to find an<md-dialog>
and it can't, so we get an error onelement[0].parentNode
:cannot find parentNode of undefined
.@gkalpak I think it's definitely similar, but we do assume that the raw content will have a dialog. I think the test was passing erroneously because we were swallowing an error that in 1.6 was getting through.
In fact, the test description talks about the
<md-dialog>
, so I think this was just an oversight.How do you think we could make this better or more clear? Do you mean adding some documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test was indeed passed erroneously. From a quick look at the docs, it's not clear what the user should pass as template if
atuoWrap
is false.<md-dialog>
?<md-dialog>
?(Based on the test I assume (3) isn't an option. If (2) is an option, then I would test for that here. If only (1) is possible, then I think the test above covers it, so this might be redundant.)
But, yeah, I meant that the docs should be more explicit (unless I missed that).