mardi 23 février 2016

JavaScript Jasmine testing function within function does not work

I already was looking for this issue and found this: Jasmine - How to spy on a function call within a function?

Nicely explained and I thought I found my remedy :) Unfortunatly this solution could not solve my problem right. Therefore I try to ask you guys if you might help me out!

describe("addSlide", function(){
it("should pass an argument to foreign API", function(){
  spyOn(testSlider, "addSlide");
  spyOn($slider, "slick");
  testSlider.addSlide(dummyHTML);
  expect($slider.addSlide).toHaveBeenCalledWith(dummyHTML);
})});

should test this:

this.addSlide = function(html) {
$slider.slick("slickAdd", html);
I.countSlides();};


I just want to test if $slider.slick has been called with the given parameter html. Nothing more :(

These are my error messages:

ERROR [PhantomJS 1.9.8 (Windows 7 0.0.0) | Slider, addSlide | should pass an argument to foreign API]: TypeError: 'undefined' is not a function (evaluating '$slider.slick(options.slider.config)') at .../Slider/Slider.js?a585af2d6e6285533e0bd5edae86ac0fae39641f:9 at .../test/src/SliderTest.js?86a9ef3313104f16dea9a358863e04dc060ca5d5:19


ERROR [PhantomJS 1.9.8 (Windows 7 0.0.0) | Slider, addSlide | should pass an argument to foreign API]: ReferenceError: Can't find variable: $slider at .../test/src/SliderTest.js?86a9ef3313104f16dea9a358863e04dc060ca5d5:44


ERROR [PhantomJS 1.9.8 (Windows 7 0.0.0)]: TypeError: 'undefined' is not a function (evaluating '$slider.slick(options.slider.config)') at .../Slider/Slider.js?a585af2d6e6285533e0bd5edae86ac0fae39641f:9 PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 31 (1 FAILED) (skipped 30) ERROR (0.009 secs / 0.001 secs)


I understand the error complaining about the not found variable $slider. But whats the solution to get it to work then? Also I cannot figure out what TypeError: 'undefined' is not a function (evaluating '$slider.slick(options.slider.config)') wants to tell me? I assured that this undefined is kinda a false statement because Debugging my Slider.js and calling .addSlide() shows me that this function actually is available...weird

I hope I did not spammed you guys and mybe you have a helpful hint for me !

If you need further informations than those provided - just tell me

Greets Charlie

Aucun commentaire:

Enregistrer un commentaire