My getRotation method simply gets the rotation value of the -webkit-
transform | -moz-transform property in the same way that the
Element.getOpacity method does. I've managed to get tests working by
creating two separate elements with the required properties and
running the assertions at the end, but it's still a bit confusing.
What's throwing me off even more is that the problem goes away when I
use the complement setRotation method to change the rotation the
second time around.
'should return correct values': function() {
el.setStyle('-webkit-transform', 'rotate(0deg)');
value_of(el.getRotation()).should_be(0);
el.setRotation(-90.1);
value_of(el.getRotation()).should_be(-90.1);
}
Those assertions work just fine. It's only when I use the el.setStyle
(); or the el.style[] methods that the test fails. Also of interest is
what a couple of console.log calls show. If I change the test to this:
'should return correct values': function() {
el.setStyle('-webkit-transform', 'rotate(0deg)');
console.log(el, el.getRotation());
value_of(el.getRotation()).should_be(0);
el.setStyle('-webkit-transform', 'rotate(-90.1deg)');
console.log(el, el.getRotation());
value_of(el.getRotation()).should_be(-90.1);
}
The console shows this:
<div style="-webkit-transform: rotate(0deg); "> 0
Element.Transformations.js: 9
<div style="-webkit-transform: rotate(0deg); "> 0
Element.Transformations.js:13
<div style="-webkit-transform: rotate(0deg); "> 0
Element.Transformations.js: 9
So it seems like the second el.setStyle() call isn't changing the
rotation so it makes sense the should_be(-90.1) assertion fails.
Thinking it might be a concurrency issue, I open up the console in the
JSSpec page and view the el variable since it's a global variable. The
output is this.
> el
<div style="-webkit-transform: rotate(0deg); ">
And finally I try the setStyle method again to ensure that it actually
works as follows:
> el.setStyle('-webkit-transform', 'rotate(-90.1deg)');
<div style="-webkit-transform: rotate(-90.1deg); ">
Which leaves me stumped since the setStyle method seems to be working
correctly outside of the tests. Yet inside it's not changing the
element.
On Nov 29, 3:44 pm, Aaron Newton <[email protected]> wrote:
> doesn't the effect have a duration? if so, it's rotating it over a duration
> while your assertion is happening immediately. You can't really test things
> like Fx w/ Specs - anything that is asynchronous.
>
>
>
> On Sat, Nov 28, 2009 at 11:55 PM, pradador <[email protected]> wrote:
> > I'm trying to learn how to use JSSpec and I'm having issues with this
> > test. I can't figure out why on earth it fails and I thought maybe one
> > of the MooTools people can share some insight. Here's the relevant
> > code:
>
> >http://gist.github.com/244835
>
> > I can't understand why it says the test on line 9 states (should be:
> > -90.1) when it really says should_be(0). If I add another "el = new
> > Element('div')" in between the tests, the problem goes away. Any
> > thoughts?