Skip to content

Commit

Permalink
props tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasso committed Apr 24, 2017
1 parent cd833af commit ad0ddc9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test/attributes.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import expect from 'expect';
import init from '../src/';

describe('attributes', function testDataset() {
describe('attributes', function testAttributes() {
this.timeout(30000);

let root;
Expand Down
81 changes: 52 additions & 29 deletions test/props.spec.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,68 @@
/*
import expect from 'expect';
import asmDom from '../src/';
import init from '../src/';

describe('dataset', function testDataset() {
this.timeout(5000);
describe('props', function testProps() {
this.timeout(30000);

const vdom = asmDom();
const { h, patch } = vdom;
let root;
let vdom;
let h;
let patch;

const clearDOM = () => {
before((done) => {
init().then((asmDom) => {
vdom = asmDom;
h = vdom.h;
patch = vdom.patch;
done();
});
});

beforeEach(() => {
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}

root = document.createElement('div');
root.setAttribute('id', 'root');
document.body.appendChild(root);
};
beforeEach(clearDOM);
it('handles string conversions', () => {
const vnode = h('i', {
'data-empty': '',
'data-dash': '-',
'data-dashed': 'foo-bar',
'data-camel': 'fooBar',
'data-integer': 0,
'data-float': 0.1,
});
});

it('should create elements with props', () => {
const vnode = h('div', { raw: { src: 'http://localhost/' } });
patch(root, vnode);
const elm = document.body.firstChild;
expect(elm.src).toEqual('http://localhost/');
vdom.deleteVNode(vnode);
});

it('changes an elements props', () => {
const vnode = h('a', { raw: { src: 'http://other/' } });
const vnode2 = h('a', { raw: { src: 'http://localhost/' } });
patch(root, vnode);
patch(vnode, vnode2);
const elm = document.body.firstChild;
expect(elm.src).toEqual('http://localhost/');
});

it('preserves memoized props', () => {
const props = { src: 'http://other/' };
const vnode = h('a', { raw: props });
const vnode2 = h('a', { raw: props });
patch(root, vnode);
let elm = document.body.firstChild;
expect(elm.src, 'http://other/');
patch(vnode, vnode2);
elm = document.body.firstChild;
expect(elm.src).toEqual('http://other/');
});

const elmPtr = patch(root, vnode);
it('removes an elements props', () => {
const vnode = h('a', { raw: { src: 'http://other/' } });
const vnode2 = h('a');
patch(root, vnode);
patch(vnode, vnode2);
const elm = document.body.firstChild;
expect(elm.getAttribute('data-empty')).toEqual('');
expect(elm.getAttribute('data-dash')).toEqual('-');
expect(elm.getAttribute('data-dashed')).toEqual('foo-bar');
expect(elm.getAttribute('data-camel')).toEqual('fooBar');
expect(elm.getAttribute('data-integer')).toEqual('0');
expect(elm.getAttribute('data-float')).toEqual('0.1');
vdom.deleteVNode(elmPtr);
expect(elm.src).toEqual(undefined);
});
});
*/

0 comments on commit ad0ddc9

Please sign in to comment.