[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

@@ -15,6 +15,7 @@ define(
mockElement,
mockCanvas,
mockGL,
mockCancelInterval,
mctChart;
beforeEach(function () {
@@ -23,9 +24,10 @@ define(
mockLog =
jasmine.createSpyObj("$log", ["warn", "info", "debug"]);
mockScope =
jasmine.createSpyObj("$scope", ["$watchCollection"]);
jasmine.createSpyObj("$scope", ["$watchCollection", "$on"]);
mockElement =
jasmine.createSpyObj("element", ["find"]);
mockCancelInterval = jasmine.createSpy("cancelInterval");
// mct-chart uses GLChart, so it needs WebGL API
@@ -70,6 +72,7 @@ define(
mockElement.find.andReturn([mockCanvas]);
mockCanvas.getContext.andReturn(mockGL);
mockInterval.andReturn(mockCancelInterval);
mctChart = new MCTChart(mockInterval, mockLog);
});
@@ -150,6 +153,26 @@ define(
expect(mockLog.warn).not.toHaveBeenCalled();
});
// Avoid resource leaks
it("stops polling for size changes on destroy", function () {
mctChart.link(mockScope, mockElement);
// Should be listening for a destroy event
expect(mockScope.$on).toHaveBeenCalledWith(
"$destroy",
jasmine.any(Function)
);
// Precondition - interval still active
expect(mockCancelInterval).not.toHaveBeenCalled();
// Broadcast a $destroy
mockScope.$on.mostRecentCall.args[1]();
// Should have stopped the interval
expect(mockCancelInterval).toHaveBeenCalled();
});
});
}
);