-
Notifications
You must be signed in to change notification settings - Fork 27.4k
perf($animate): listen for document visibility changes #14519
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 |
---|---|---|
|
@@ -27,3 +27,32 @@ describe('$document', function() { | |
}); | ||
}); | ||
}); | ||
|
||
|
||
describe('$$isDocumentHidden', function() { | ||
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 think there should be a test that shows the value changing when 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, but I found it quite complicated to do that. Because you'd have to mock the document (because hidden isn't writable), and still have it accept event listeners and fire events. 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 don't think you need all that. I think all you need it mocking But this is aff the top of my head, so I might be missing something. If it's not too complicated I'd say let's add some. |
||
|
||
it('should return false by default', inject(function($$isDocumentHidden, $document) { | ||
expect($$isDocumentHidden()).toBeFalsy(); // undefined in browsers that don't support visibility | ||
})); | ||
|
||
it('should listen on the visibilitychange event', function() { | ||
|
||
var spy = spyOn(document, 'addEventListener').and.callThrough(); | ||
|
||
inject(function($$isDocumentHidden, $document) { | ||
expect(spy.calls.mostRecent().args[0]).toBe('visibilitychange'); | ||
expect(spy.calls.mostRecent().args[1]).toEqual(jasmine.any(Function)); | ||
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. Since we don't really care if it was the most recent, you could also usr 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 used that before, but there's a difference between jquery 2.1 and jqlite, jquery calls addEventListener with the third argument set to false, jqlite doesn't set the argument. That's why I used mostRecent. 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. So, that's what you were talking about with @mgol :) |
||
}); | ||
|
||
}); | ||
|
||
it('should remove the listener when the $rootScope is destroyed', function() { | ||
var spy = spyOn(document, 'removeEventListener').and.callThrough(); | ||
|
||
inject(function($$isDocumentHidden, $rootScope) { | ||
$rootScope.$destroy(); | ||
expect(spy.calls.mostRecent().args[0]).toBe('visibilitychange'); | ||
expect(spy.calls.mostRecent().args[1]).toEqual(jasmine.any(Function)); | ||
}); | ||
}); | ||
}); |
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.
You are checking if
doc
is available in line 42 but not here. Is this correct? Is the check above necessary?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 the check was originally introduced by @matsko in case the document isn't available. I assume that when the document isn't available I can't add a listener anyway.