Get help with testing, discuss unit testing strategies etc.


Post by andrey11231990 »

Hi.
Now I am trying siesta 3.1.0 and found code which seems strange to me
inside of method
testMethodDone: function() {
we do
tearDown.call(this);
and inside of
this.tearDown
tearDown : function (callback, errback) {
        callback.call(this)
},
so in situations, when my test does not have any teardown, then default teardown method will be called. But while call there no arguments to send, but inside of method we try to execute callback.call - so here will be exception
Cannot read property 'call' of undefined
is it a bug ?

Post by nickolay »

Hi,

No, its not. The "tearDown" method is provided with the callback, which should be called, once the tear down process is completed (so-called asynchronous method).

I assume you are using your own test class, can you post the whole source file for it?

Post by andrey11231990 »

Hi.
I simplified my test:
startTest(function(test) {
test.testMethod({
					name: "test",
					setUp: function() {
						Ext.define("my", {
							destroy: function() {},
							init: function(callback) {
								this.value = {};
								callback();
							},
							value: null
						});
						var viewModelMock = Ext.create("my");
						test.data.viewModelMock = viewModelMock;
					},
					method: function() {
						var viewModelMock = test.data.viewModelMock;
						test.chain(
							function(next) {
								viewModelMock.init(next);
							},
							function(next) {
								var profileColumnValue = viewModelMock.value;
								test.isObject(profileColumnValue, test.name + " - set profile data to attribute");
								test.testMethodDone();
								next();
							},
							function() {
								viewModelMock.destroy();
								delete test.data.viewModelMock;
							}
						);
					}
				});
});
With this test I can see error message:
test: tearDown failed with exception - Cannot read property 'call' of undefined
so i did not override tearDown function not for test.tearDown, not for testMethod, so it looks for default realisation.
can you reproduce error with this example and how i need to rewrite this test, so it start to work correctly ?

and one more question - in 3 version in test.tearDown we could see two arguments - success and error callbacks. If i rewrite test.tearDown, than I need necessarily call one of this callbacks or otherwise it will throw exception by timeout - am I properly understand this ?

Post by nickolay »

Hello,
andrey11231990 wrote: can you reproduce error with this example and how i need to rewrite this test, so it start to work correctly ?
Since I don't see the implementation of the `test.testMethod` I can not say anything. Try to enable "break on error" in chrome debugger and see what is causing the exception?
andrey11231990 wrote: and one more question - in 3 version in test.tearDown we could see two arguments - success and error callbacks. If i rewrite test.tearDown, than I need necessarily call one of this callbacks or otherwise it will throw exception by timeout - am I properly understand this ?
Thats correct.

Post by andrey11231990 »

nickolay wrote: Since I don't see the implementation of the `test.testMethod` I can not say anything. Try to enable "break on error" in chrome debugger and see what is causing the exception?.
I posted testMethod that fail for me. And I ask - can you reproduce it too with method that I posted ?

Post by nickolay »

No, I can not reproduce. The code you posted, contains a call to the `testMethod`
startTest(function(test) {
    test.testMethod({
    ....
});
which is defined somewhere in your test class implementation. If you can post a fully reproducible example I can take a look.

Post by andrey11231990 »

i've got some legacy code and i thinked that this was part of siesta. but after debug i found error inside of that code. so thank you for help. with siesta all ok. thanks :)

Post Reply