app-decorators
Version:
Collection of useful ES7 Decorators, writtin in ES6, that can be used for building webapps
84 lines (66 loc) • 3.11 kB
JavaScript
System.register(['app-decorators/src/libs/element-to-function', '../../src/helpers/extract-dom-properties'], function (_export, _context) {
"use strict";
var _elementToFunc, extractDomProperties;
return {
setters: [function (_appDecoratorsSrcLibsElementToFunction) {
_elementToFunc = _appDecoratorsSrcLibsElementToFunction.default;
}, function (_srcHelpersExtractDomProperties) {
extractDomProperties = _srcHelpersExtractDomProperties.extractDomProperties;
}],
execute: function () {
describe('extractDecoratorProperties', function () {
function MockElement(attributes) {
this.attributes = attributes;
}
MockElement.prototype = {
// simulate removing of removeAttribute
removeAttribute: function removeAttribute(attribute) {
for (var attr in this.attributes) {
if (!this.attributes.hasOwnProperty(attr)) continue;
if (this.attributes[attr].name === attribute) {
delete this.attributes[attr];
}
}
}
};
it('it should return objectlist of dom attributes that matched of @view.bind', function () {
var MockDomNode = new MockElement({
0: { name: '@view.bind.b', value: 'baz' },
1: { name: 'class', value: 'foo' },
2: { name: '@view.bind.x', value: 'bar' }
});
var viewAttributeList = extractDomProperties(MockDomNode, /^@view\.bind\.(\S+)$/i, true);
// positiv test
viewAttributeList.should.have.propertyByPath('x').eql('bar');
viewAttributeList.should.have.propertyByPath('b').eql('baz');
// negativ test
viewAttributeList.should.not.have.propertyByPath('class');
// the third argument for getDomAttributes removes the dom attribute
Object.keys(MockDomNode.attributes).should.have.length(1);
MockDomNode.attributes.should.have.propertyByPath(1, 'name').eql('class');
var regularAttributeList = extractDomProperties(MockDomNode);
regularAttributeList.should.have.propertyByPath('class').eql('foo');
});
it('it should return objectlist of dom attributes that matched of @on', function () {
var MockDomNode = new MockElement({
0: { name: '@on(click)', value: 'clickFunction()' },
1: { name: 'id', value: 'bazi' },
2: { name: '@on(mousedown)', value: 'mousedownFunction()' }
});
var viewAttributeList = extractDomProperties(MockDomNode, /^@on\((\S+)\)$/i, true);
// positiv test
viewAttributeList.should.have.propertyByPath('click').eql('clickFunction()');
viewAttributeList.should.have.propertyByPath('mousedown').eql('mousedownFunction()');
// negativ test
viewAttributeList.should.not.have.propertyByPath('id');
// the third argument for getDomAttributes removes the dom attribute
Object.keys(MockDomNode.attributes).should.have.length(1);
MockDomNode.attributes.should.have.propertyByPath(1, 'name').eql('id');
var regularAttributeList = extractDomProperties(MockDomNode);
regularAttributeList.should.have.propertyByPath('id').eql('bazi');
});
});
}
};
});
//# sourceMappingURL=extract-dom-properties.spec.js.map