[Performance] Update specs

Add tests to verify that directives stop polling after their
scope is destroyed (to prevent resource leaks); those changes
address resource leaks identified in the context of WTD-717.
This commit is contained in:
Victor Woeltjen
2015-01-27 08:50:09 -08:00
parent d192d611f9
commit 6947e0aa42
2 changed files with 51 additions and 2 deletions

View File

@@ -14,7 +14,7 @@ define(
beforeEach(function () {
mockTimeout = jasmine.createSpy("$timeout");
mockScope = jasmine.createSpyObj("$scope", ["$eval"]);
mockScope = jasmine.createSpyObj("$scope", ["$eval", "$on"]);
testElement = { offsetWidth: 100, offsetHeight: 200 };
testAttrs = { mctResize: "some-expr" };
@@ -63,6 +63,32 @@ define(
);
});
it("stops size checking for size changes after destroy", function () {
mctResize.link(mockScope, [testElement], testAttrs);
// First, make sure there's a $destroy observer
expect(mockScope.$on)
.toHaveBeenCalledWith("$destroy", jasmine.any(Function));
// Should have scheduled the first timeout
expect(mockTimeout.calls.length).toEqual(1);
// Fire the timeout
mockTimeout.mostRecentCall.args[0]();
// Should have scheduled another timeout
expect(mockTimeout.calls.length).toEqual(2);
// Broadcast a destroy event
mockScope.$on.mostRecentCall.args[1]();
// Fire the timeout
mockTimeout.mostRecentCall.args[0]();
// Should NOT have scheduled another timeout
expect(mockTimeout.calls.length).toEqual(2);
});
});
}
);