1 | 'use strict';
|
2 |
|
3 | var chai = require('chai'),
|
4 | expect = chai.expect,
|
5 | helpers = require('../lib/helpers');
|
6 |
|
7 | describe('helpers', function () {
|
8 | describe('#tag', function () {
|
9 | it('returns an opening tag with attributes', function () {
|
10 | var el = {
|
11 | type: 'tag',
|
12 | name: 'foo',
|
13 | attribs: {
|
14 | bar: 'bat'
|
15 | }
|
16 | };
|
17 |
|
18 | expect(helpers.tag(el)).to.be.equal('<foo bar="bat">');
|
19 | });
|
20 |
|
21 | it('returns an opening tag without attributes', function () {
|
22 | var el = {
|
23 | type: 'tag',
|
24 | name: 'foo'
|
25 | };
|
26 |
|
27 | expect(helpers.tag(el)).to.be.equal('<foo>');
|
28 | });
|
29 | });
|
30 |
|
31 | describe('#text', function () {
|
32 | it('returns the element\'s contents', function () {
|
33 | var el = {
|
34 | type: 'text',
|
35 | data: 'some text'
|
36 | };
|
37 |
|
38 | expect(helpers.text(el)).to.be.equal('some text');
|
39 | });
|
40 | });
|
41 |
|
42 | describe('#comment', function () {
|
43 | it('returns the element\'s contents', function () {
|
44 | var el = {
|
45 | type: 'comment',
|
46 | data: 'some text'
|
47 | };
|
48 |
|
49 | expect(helpers.comment(el)).to.be.equal('<!--some text-->');
|
50 | });
|
51 | });
|
52 |
|
53 | describe('#directive', function () {
|
54 | it('returns the element\'s contents', function () {
|
55 | var el = {
|
56 | type: 'directive',
|
57 | data: '!DOCTYPE html'
|
58 | };
|
59 |
|
60 | expect(helpers.directive(el)).to.be.equal('<!DOCTYPE html>');
|
61 | });
|
62 | });
|
63 |
|
64 | describe('#close', function () {
|
65 | it('closes non-singular tags', function () {
|
66 | var el = {
|
67 | type: 'tag',
|
68 | name: 'foo'
|
69 | };
|
70 |
|
71 | expect(helpers.close(el)).to.be.equal('</foo>');
|
72 | });
|
73 |
|
74 | it('does not close singular tags', function () {
|
75 | var el = {
|
76 | type: 'tag',
|
77 | name: 'img'
|
78 | };
|
79 |
|
80 | expect(helpers.close(el)).to.be.equal('');
|
81 | });
|
82 |
|
83 | it('does not close non-tags', function () {
|
84 | var el = {
|
85 | type: 'foo',
|
86 | name: 'bar'
|
87 | };
|
88 |
|
89 | expect(helpers.close(el)).to.be.equal('');
|
90 | });
|
91 | });
|
92 | });
|