9 describe('Fx.Morph', function(){
11 beforeEach(function(){
12 this.clock = sinon.useFakeTimers();
14 this.div = new Element('div', {'class': 'pos-abs-left'});
15 this.style = new Element('style');
18 ' position: absolute;',
26 [this.style, this.div].invoke('inject', document.body);
28 if (this.style.styleSheet) this.style.styleSheet.cssText = definition;
29 else this.style.set('text', definition);
35 [this.div, this.style].invoke('destroy');
38 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);
62 it('should set morph options with the element getter and setter', function(){
63 var element = new Element('div');
65 element.set('morph', {
69 expect(element.get('morph').options.duration).to.equal(100);
72 it('should morph between % units', function(){
73 sinon.spy(this.div, 'setStyle');
74 this.div.set('morph', {unit : '%'}).morph({'left': [10, 50]});
76 this.clock.tick(1000);
78 expect(this.div.setStyle.calledWith('left', ['10%'])).to.equal(true);
79 expect(this.div.setStyle.calledWith('left', ['50%'])).to.equal(true);
81 this.div.setStyle.restore();
84 it('it should morph when the unit option is set, but an empty value', function(){
85 this.div.set('morph', {
95 expect(this.div.getStyle('top')).to.equal('100px');
96 expect(this.div.getStyle('opacity')).to.equal(1);
99 it('it should morph when the unit option is set, but the style value is a number', function(){
111 this.clock.tick(150);
113 expect(this.div.getStyle('top')).to.equal('100px');
114 expect(this.div.getStyle('opacity')).to.equal(1);