Hi,
I have some behavior that I think is wrong, when I have f.ex. the
following specification:
describe 'FeedBack'
before_each
div = elements('<div/>')
end
after_each
end
describe 'displaySuccessMessage(text, callBack)'
it 'will be able to use jQuery syntax'
$(div).displaySuccessMessage('test', null)
true.should.be_true
end
it 'will append a div with the message'
$(div).displaySuccessMessage('test', null)
$(div).html().should.match /^<div id=\"displaySuccessMessage\"
class=\"success\".*>test<\/div>$/
end
it 'will return the original object so it is chainable'
$(div).displaySuccessMessage('test', null).html().should.match
/^<div id=\"displaySuccessMessage\" class=\"success\".*>test<\/div>$/
end
it 'will be hidden at first'
$(div).displaySuccessMessage('test',
null).find('div').css('display').
should.be "none"
end
it 'will be visible after 500 milliseconds'
tick(10)
$(div).displaySuccessMessage('test',
null).find('div').css('display').
should.be "block"
end
end
end
And implementation:
(function($){
$.fn.displaySuccessMessage = function(messageText, callBack){
var $this = this;
$this.html('');
$this.append("<div id=\"displaySuccessMessage\" class=\"success\"
style=\"\">"+ messageText +"</div>");
$this.find('#displaySuccessMessage').css('display', 'none');
setTimeout(function(){
console.log($this.find('#displaySuccessMessage').css('display'));
$this.find('#displaySuccessMessage').fadeIn(400);
console.log($this.find('#displaySuccessMessage').css('display'));
}, 10);
return this;
};
})(jQuery);
Then the 'will be visible after 500 milliseconds' will fail, but when
you look at the console then you can clearly see that the timeout has
been triggered. The other weird thing is that this timeout is being
triggered for each test in the file. So not just for the tests that
have the tick() set for the right value. I would have assumed that
each test would be scoped individually?
Just to check if it had anything to do with the timer I also tried
this instead with the same results:
http://monket.net/blog/wp-content/uploads/2009/07/jsUnitMockTimeout.js
But when I move the $(div).displaySuccessMessage('test', null) into
the before_each then the scoping seems to be ok.
And one last thing is when using fadeIn or something like that then
nothing works anymore, is there a trick around that? How can the
callback for the fadeIn and fadfeOut type of functions be called? This
one is actually a nasty one which would prevent me from testing most
of the functionality.
-Mark
--
Mark Nijhof
Cre8ive Thought
m: 0047 95 00 99 37
e:
mark....@cre8ivethought.com
w:
www.cre8ivethought.com
--
JSpec thanks you for your interest and support! To post simply reply
to this email.
documentation:
http://jspec.info
unsubscribe:
jspec+un...@googlegroups.com
group:
http://groups.google.com/group/jspec