keripix
5 Dec 2011, 12:07 AM
var ctrl = Application.getController("document.DocumentUpload"),
pathField = Ext.ComponentQuery.query("#pathField")[0];
expect(ctrl).toBeDefined(); //first test
spyOn(ctrl,'validateFile');
pathField.fireEvent("change"); // second test
expect(ctrl.validateFile).toHaveBeenCalled();
The above code is a simplified version of the real one.
The first test passed, but the second one failed. I then added:
console.log("validate has been called");
inside the validateFile method, then checked while running the test. The above log was called. So its correct if i assume the method was actually called, right?
If that's the case, then why jasmine failed?
Well, I then tried to modify the test and validateFile() method. I added a new property to my controller:
validateFileHasBeenCalled : false
then inside validateFile i set the above property to true, so that when i run the test, I can check wether validateFile has been called. Inside validateFIle():
this.validateFileHasBeenCalled = true;
The test passed.
So, im still very curious, why did jasmine failed on my first try? Did i do something wrong? Or have i misunderstood something?
PS: im still new to javascript, extjs and tdd.
Thanks in advance
pathField = Ext.ComponentQuery.query("#pathField")[0];
expect(ctrl).toBeDefined(); //first test
spyOn(ctrl,'validateFile');
pathField.fireEvent("change"); // second test
expect(ctrl.validateFile).toHaveBeenCalled();
The above code is a simplified version of the real one.
The first test passed, but the second one failed. I then added:
console.log("validate has been called");
inside the validateFile method, then checked while running the test. The above log was called. So its correct if i assume the method was actually called, right?
If that's the case, then why jasmine failed?
Well, I then tried to modify the test and validateFile() method. I added a new property to my controller:
validateFileHasBeenCalled : false
then inside validateFile i set the above property to true, so that when i run the test, I can check wether validateFile has been called. Inside validateFIle():
this.validateFileHasBeenCalled = true;
The test passed.
So, im still very curious, why did jasmine failed on my first try? Did i do something wrong? Or have i misunderstood something?
PS: im still new to javascript, extjs and tdd.
Thanks in advance