Permalink
Browse files

Add createElement tests.

  • Loading branch information...
sranso committed Oct 5, 2016
1 parent 25576bb commit 5bfe9d52ba35347c184c6e6ba266dd96a36c2910
Showing with 64 additions and 0 deletions.
  1. +1 −0 README.md
  2. +61 −0 test/createElement.js
  3. +2 −0 test/createNode.js
View
@@ -19,6 +19,7 @@ $ npm run test
- interact with browser APIs
- use ES6
- set up a project
+- practice TDD
###Resources:
View
@@ -0,0 +1,61 @@
+import { createElement,
+ createElementAtt,
+ createElementStyles } from '../src/createElement';
+import createNode from '../src/createNode';
+
+import { expect } from 'chai';
+
+describe('createElement module', () => {
+ describe('createElement', () => {
+ let atts, children, node;
+ beforeEach(() => {
+ atts = {
+ 'style': {
+ 'text-align': 'center',
+ 'color': 'blue',
+ 'margin': '20px'
+ },
+ 'id': 'vdom'
+ };
+ children = [
+ [
+ 'p', {
+ 'style': {
+ 'font-size': '20px;'
+ }
+ },
+ [12345]
+ ]
+ ];
+ node = createNode('div', atts, children);
+ });
+
+ it('should return an error if node is invalid', () => {
+ expect(createElement).to.throw(Error);
+ });
+
+ it('should return an html string', () => {
+ expect(createElement(node)).to.be.have.string('<div');
+ expect(createElement(node)).to.be.have.string('</div>');
+ expect(createElement(node)).to.be.have.string('<p');
+ expect(createElement(node)).to.be.have.string('</p>');
+ });
+ });
+
+ describe('createElementAtt', () => {
+ it('should return an html atts string', () => {
+ expect(createElementAtt('id', 'sup')).to.have.string('id="sup"');
+ expect(createElementAtt('src', '/some/place')).to.have.string('src="/some/place"');
+ expect(createElementAtt('title', 'the best thing ever')).to.have.string('title="the best thing ever"');
+ });
+ });
+
+ describe('createElementStyles', () => {
+ it('should return an html styles atts string', () => {
+ expect(createElementStyles({'width': '20px', 'height': '10px'})).to.have.string('width: 20px');
+ expect(createElementStyles({'width': '20px', 'height': '10px'})).to.have.string('height: 10px');
+ expect(createElementStyles({'width': '20px', 'height': '10px'})).to.have.string('style=');
+ });
+ });
+
+});
View
@@ -24,7 +24,9 @@ describe('createNode module', () => {
]
];
const node = createNode('div', atts, children);
+ const simpleNode = createNode('div');
expect(node.length).to.equal(3);
+ expect(simpleNode.length).to.equal(3);
});
});
});

0 comments on commit 5bfe9d5

Please sign in to comment.