Assuming you enter DocumentTypes in your controller or whatever you open OpenMail in this function, you can make fun of it when you run tests. One way to do this might be to use the $ provision service.
This layout might look like this if you use karma-chai-spies:
stubs = { DocumentTypes: { getDocument: chai.spy(function(callback) { callback({ result: [ "type" ] }); }) } };
Then provide it with $ security in your unit tests:
beforeEach(function() { module(function($provide) { $provide.value("DocumentTypes", stubs.DocumentTypes); }); });
The test itself could look something like this using karma mocha and karma tea:
it("should test open mail", function() { var controller = $controller('myController', { $scope: stubs.$scope }); stubs.$scope.openMail("mail"); expect(stubs.$scope.documentTypes).to.deep.equal([ "type" ]); expect(stubs.DocumentTypes.getDocument).to.have.been.called.once(); });
source share