thanks in advance, I am trying to test a function that is called on ajax success callback and then inside a forEach. (trackTaxonomyEvent())
But I am always getting
Error: Expected spy trackTaxonomyEvent to have been called
If I move the function out of the forEach it works.
code.js
saveFanzones: function(closeOnSave) {
this.selectedTaxonomyCollection.create({
taxonomy_ids: newTaxaonomiesId.join(',')
}, {
success: function() {
_.forEach(this.selectedTaxonomyCollection.where({
user_selected: true
}), function(fanzoneModel) {
var params = {
id: fanzoneModel.get('id')
};
this.trackTaxonomyEvent('fanzone:join',params);
}.bind(this));
}.bind(this)
});
});
code.spec.js
it('Ajax call correct URL', function() {
spyOn($, 'ajax').and.callFake(function(params) {
params.success('1');
});
spyOn(view, 'trackTaxonomyEvent').and.callThrough();
view.saveFanzones();
expect(view.trackTaxonomyEvent).toHaveBeenCalled();
});
Aucun commentaire:
Enregistrer un commentaire