liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
define([
    'intern!tdd',
    'intern/chai!assert',
    'dojo/_base/declare',
    'dojo/on',
    'dgrid/List',
    'dgrid/OnDemandList',
    'dstore/Memory'
], function (test, assert, declare, on, List, OnDemandList, Memory) {
    test.suite('createDestroy', function () {
        test.test('no params list', function () {
            var list = new List();
            document.body.appendChild(list.domNode);
            list.startup();
            list.renderArray([ 'foo', 'bar', 'baz' ]);
 
            assert.strictEqual(list.contentNode.children.length, 3,
                'List\'s contentNode has expected number of children after renderArray');
 
            list.destroy();
            assert.notStrictEqual(document.body, list.parentNode,
                'List is removed from body after destroy');
        });
 
        // Test for issue #1030
        test.test('OnDemandList#refresh should not throw error if domNode is nullified when destroyed', function () {
            var CustomList = declare(OnDemandList, {
                destroy: function () {
                    this.inherited(arguments);
                    // If dgrid is mixed in with dijit hierarchy, destroy() may unset domNode
                    this.domNode = null;
                }
            });
            var dfd = this.async();
 
            var grid = new CustomList({
                collection: new Memory({ data: [
                    { id: 1 },
                    { id: 2 },
                    { id: 3 }
                ] })
            });
            document.body.appendChild(grid.domNode);
            grid.startup();
 
            assert.strictEqual(grid.contentNode.children.length, 5,
                'Grid\'s contentNode has expected number of children after renderArray');
 
            grid.destroy();
 
            assert.notStrictEqual(document.body, grid.parentNode, 'Grid is removed from body after destroy');
 
            // Start watching for global error. There should be none.
            // (Can't use assert.doesNotThrow since this will be thrown asynchronously)
            var errorCatchingHandle = on(window, 'error', function (error) {
                dfd.reject(error);
            });
 
            // The error had been happening in a callback queued with setTimeout(0) in
            // refresh(). Here we queue another which will run after that one to close
            // out the test.
            setTimeout(dfd.callback(function () {
                errorCatchingHandle.remove();
            }), 0);
        });
    });
});