Skip to content

Instantly share code, notes, and snippets.

@revolunet
Last active April 23, 2018 08:02
Show Gist options
  • Save revolunet/6722092 to your computer and use it in GitHub Desktop.
Save revolunet/6722092 to your computer and use it in GitHub Desktop.
Jasmine test angular-translate calls
/*
silly way to ensure $translate service has been called with correct key and arguments
*/
var $translate;
beforeEach(inject(function (_$translate_) {
$translate = function() {
$translate.spy.apply(this, arguments);
};
$translate.spy = function() {};
spyOn($translate, 'spy').andCallFake(function() {
// dummy
});
});
it('should call translate service with correct parameters', function() {
// check we call $translate('translation-key-to-check', {username: 'Bill Cosby'});
expect($translate.spy).toHaveBeenCalledWith('translation-key-to-check', {username: 'Bill Cosby'});
});
@BBlackwo
Copy link

Thanks @ralfius your code worked for me too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment