8 describe('Fx.Morph', function(){
10 beforeEach(function(){
11 this.clock = sinon.useFakeTimers();
13 this.div = new Element('div', {'class': 'pos-abs-left'});
14 this.style = new Element('style');
17 'position: absolute;',
25 [this.style, this.div].invoke('inject', document.body);
27 if (this.style.styleSheet) this.style.styleSheet.cssText = definition;
28 else this.style.set('text', definition);
34 [this.div, this.style].invoke('destroy');
37 it('should morph the style of an element', function(){
39 var element = new Element('div', {
44 }).inject(document.body);
46 var fx = new Fx.Morph(element, {
57 expect(element.getStyle('height').toInt()).to.equal(50);
58 expect(element.getStyle('width').toInt()).to.equal(50);
63 it('should set morph options with the element getter and setter', function(){
65 var element = new Element('div');
67 element.set('morph', {
71 expect(element.get('morph').options.duration).to.equal(100);
75 it('should morph between % units', function(){
76 sinon.spy(this.div, 'setStyle');
77 this.div.set('morph', {unit : '%'}).morph({'left': [10, 50]});
79 this.clock.tick(1000);
81 expect(this.div.setStyle.calledWith('left', ['10%'])).to.equal(true);
82 expect(this.div.setStyle.calledWith('left', ['50%'])).to.equal(true);
84 this.div.setStyle.restore();
87 it('it should morph when the unit option is set, but an empty value', function(){
89 this.div.set('morph', {
99 expect(this.div.getStyle('top')).to.equal('100px');
100 expect(this.div.getStyle('opacity')).to.equal(1);
104 it('it should morph when the unit option is set, but the style value is a number', function(){
117 this.clock.tick(150);
119 expect(this.div.getStyle('top')).to.equal('100px');
120 expect(this.div.getStyle('opacity')).to.equal(1);