Created
October 7, 2014 23:03
-
-
Save dac09/db750d648c8bad694907 to your computer and use it in GitHub Desktop.
Constants in Jasmine unit tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Test', function() { | |
beforeEach(function() { | |
module('App', function($provide) { | |
$provide.constant('CSRF_TOKEN', 'MOCK_CONSTANT'); // <= mock your constant | |
}); | |
}); | |
// Tests go here | |
}); |
How do you use that constant value in your specs?
This helped. Thanks dac09.
georgeblake,
In my case, I was writing a test for a custom filter, which made use of a constant.
After specifying my constant, I injected it, for my filter to use. Like so:
beforeEach(function() {
module("moduleName", function($provide) {
$provide.constant("mockConstantName", mockConstantValue);
});
});
var filter;
beforeEach(inject(function (mockConstantName, _$filter_) {
filter = _$filter_("filterName");
}));
it("should return 'result' ", function () {
expect(filter("input")).toEqual("result");
});
Hope this helps.
@dac09 you saved my day dude 🍺
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great for $httpBackend tests, as it lets you test if $http requestst use env / constants / config