Skip to content

Instantly share code, notes, and snippets.

@arian
Created February 18, 2012 16:57
Show Gist options
  • Save arian/1860182 to your computer and use it in GitHub Desktop.
Save arian/1860182 to your computer and use it in GitHub Desktop.
describe('getStyle height / width / margin with CSS', function(){
var style, element;
it('[beforeAll]', function(){
var className = String.uniqueID();
style = $(document.createElement('style'));
style.type = 'text/css';
var definition = [
'.' + className + '{',
'height: 200px;',
'width: 50%;',
'margin-left: 20%;',
'}'
].join('');
// fix this, see https://github.com/mootools/mootools-core/issues/2265
if (style.styleSheet) style.styleSheet.cssText = definition;
else style.set('text', definition);
document.head.appendChild(style);
element = new Element('div', {
'class': className,
text: 'yo'
}).inject(document.body);
});
it('should get the height from the CSS', function(){
expect(element.getStyle('height')).toEqual('200px');
});
it('should get the width from the CSS', function(){
expect(element.getStyle('width')).toMatch(/\d+px/);
});
it('should get the left margin from the CSS', function(){
expect(element.getStyle('margin-left')).toEqual('20%');
});
it('[afterAll]', function(){
style.destroy();
element.destroy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment