I'm getting the following error when running the entire suite of tests:
timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
After some investigation, I found out to be a memory leak issue. Looking at some heap profiling snapshot, objects still seem to be referenced and not getting garbaged collected.
Anyone know a solution that would prevent it from happening? There's some options such as going through each one of my 1000ish specs and adding afterEach
to do some clean up, but that seems like a lot of work.
Here's a sample layout of how most of my tests look like
describe('MyClassCtrl', function() {
var $httpBackend, $rootScope, ctrl;
ctrl = $rootScope = $httpBackend = null;
beforeEach(function() {
module('myApp');
inject(function($controller, $rootScope, _$httpBackend_, $stateParams) {
var $scope;
$stateParams.id = 1;
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
ctrl = $controller('MyClassCtrl', {
$scope: $scope
});
});
});
describe('#_getMyList', function() {
beforeEach(function() {
$httpBackend.expectGET("/my/app/url").respond({
my_list: [1, 2, 3]
});
ctrl._getMyList();
$httpBackend.flush();
});
it('does this', function() {
expect(ctrl.my_list).to.eql([1, 2, 3]);
});
});
});
Below are some profiling screenshots:
UPDATE
I was able to trigger a memory leak by simply wrapping one of my it
in a loop.
e.g.:
for (i = 0; i < 200; i++) {
it('does this', function() {
expect(ctrl.my_list).to.eql([1, 2, 3]);
});
}
In my tests, I set all objects within a container object and cleaned it up in an afterEach
(like the solution here) but no luck. Memory allocation still keep increasing on Chrome's Dev Timeline tool.
Thanks!