UNPKG

1.8 kBJavaScriptView Raw
1/*global describe, it */
2
3var helper = require('../lib/helper')
4 , should = require('chai').should()
5;
6
7describe('helper.simplifyNode()', function(){
8 it('should return only text when really simple', function(){
9 var input = {
10 $name: 'title',
11 $attrs: {},
12 $text: 'this is a title'
13 };
14 helper.simplifyNode(input, true).should.equal('this is a title');
15 helper.simplifyNode(input).should.not.equal('this is a title');
16 });
17
18 it('should return only attributes when really simple', function(){
19 var input = {
20 $name: 'div',
21 $attrs: {id: '34', type:'thing'},
22 };
23 helper.simplifyNode(input).should.deep.equal({$name: 'div', id: '34', type: 'thing'});
24 helper.simplifyNode(input, true).should.deep.equal({id: '34', type: 'thing'});
25 });
26
27 it('should drop unecessary properties', function(){
28 var input, output;
29
30 input = {
31 $name: 'title',
32 $attrs: {id: '34'},
33 $text: null
34 };
35 output = {
36 $name: 'title',
37 id: '34'
38 };
39 helper.simplifyNode(input).should.deep.equal(output);
40 helper.simplifyNode(input, true).should.deep.equal(input.$attrs);
41 });
42
43 it('should not simplify when things get interesting', function(){
44 var input, output;
45
46 input = {
47 $name: 'header',
48 $attrs: {id: '3'},
49 $markup: [ 'some text' ]
50 };
51
52 output = {
53 $name: 'header',
54 $attrs: {id: '3'},
55 $markup: 'some text'
56 };
57
58 helper.simplifyNode(input).should.deep.equal(output);
59 delete output.$name;
60
61 helper.simplifyNode(input, true).should.deep.equal(output);
62 });
63});