Projekt

Obecné

Profil

Stáhnout (1.54 KB) Statistiky
| Větev: | Revize:
1
var inspect = require('../');
2
var test = require('tape');
3

    
4
test('element', function (t) {
5
    t.plan(3);
6
    var elem = {
7
        nodeName: 'div',
8
        attributes: [{ name: 'class', value: 'row' }],
9
        getAttribute: function (key) { return key; },
10
        childNodes: []
11
    };
12
    var obj = [1, elem, 3];
13
    t.deepEqual(inspect(obj), '[ 1, <div class="row"></div>, 3 ]');
14
    t.deepEqual(inspect(obj, { quoteStyle: 'single' }), "[ 1, <div class='row'></div>, 3 ]");
15
    t.deepEqual(inspect(obj, { quoteStyle: 'double' }), '[ 1, <div class="row"></div>, 3 ]');
16
});
17

    
18
test('element no attr', function (t) {
19
    t.plan(1);
20
    var elem = {
21
        nodeName: 'div',
22
        getAttribute: function (key) { return key; },
23
        childNodes: []
24
    };
25
    var obj = [1, elem, 3];
26
    t.deepEqual(inspect(obj), '[ 1, <div></div>, 3 ]');
27
});
28

    
29
test('element with contents', function (t) {
30
    t.plan(1);
31
    var elem = {
32
        nodeName: 'div',
33
        getAttribute: function (key) { return key; },
34
        childNodes: [{ nodeName: 'b' }]
35
    };
36
    var obj = [1, elem, 3];
37
    t.deepEqual(inspect(obj), '[ 1, <div>...</div>, 3 ]');
38
});
39

    
40
test('element instance', function (t) {
41
    t.plan(1);
42
    var h = global.HTMLElement;
43
    global.HTMLElement = function (name, attr) {
44
        this.nodeName = name;
45
        this.attributes = attr;
46
    };
47
    global.HTMLElement.prototype.getAttribute = function () {};
48

    
49
    var elem = new global.HTMLElement('div', []);
50
    var obj = [1, elem, 3];
51
    t.deepEqual(inspect(obj), '[ 1, <div></div>, 3 ]');
52
    global.HTMLElement = h;
53
});
(4-4/14)