Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

Cleanup reset() test and usage - run testDone callback first, to allow listeneres...
[qunit.git] / addons / composite / composite-test.js
1 module( "testSuites tests", (function(){
2         var asyncTest = QUnit.asyncTest,
3                 runSuite = QUnit.runSuite;
4
5         return {
6                 setup: function(){
7                         //proxy asyncTest and runSuite
8                         QUnit.asyncTest = window.asyncTest = function( name, callback ){
9                                 ok( true, "asyncTestCalled for each suite" );
10                                 callback(); //don't acutally create tests, just call callback
11                         };
12                         QUnit.runSuite = window.runSuite = function(){
13                                 ok( true, "runSuite called for each suite" );
14                         };
15                         //ensure that subsuite's done doesn't run
16                         this.oldDone = QUnit.done;
17                 },
18                 teardown: function(){
19                         //restore
20                         QUnit.asyncTest = window.asyncTest = asyncTest;
21                         QUnit.runSuite = window.runSuite = runSuite;
22                         QUnit.done = this.oldDone;
23                 }
24         };
25 })());
26
27 test( "proper number of asyncTest and runSuite calls", function(){
28         expect( 6 );
29         QUnit.testSuites( ["one.html", "two.html", "three.html"] );
30 });
31
32 test( "done callback changed", function(){
33         QUnit.testSuites( ["dummy.html"] );
34         notEqual( this.oldDone, QUnit.done, "done callback should be set" );
35 });
36
37 module( "testStart tests", (function(){
38         var id = QUnit.id;
39         return {
40                 setup: function(){
41                         //proxy id
42                         var fakeElem = this.fakeElem = document.createElement( "div" );
43
44                         QUnit.id = function(){
45                                 return fakeElem;
46                         }
47                 },
48                 teardown: function(){
49                         QUnit.id = id;
50                 }
51         };
52 })());
53
54 test( "running message printed", function(){
55         var hello = "hello world",
56         expected = "Running " + hello + "...<br>&nbsp;";
57         QUnit.testStart( {name: hello} );
58         equal( this.fakeElem.innerHTML, expected, "innerHTML was set correctly by testStart" );
59 });
60
61 module( "testDone tests", (function(){
62         var id = QUnit.id;
63         return {
64                 setup: function(){
65                         //proxy id
66                         var fakeElem = this.fakeElem = document.createElement( "div" );
67                         fakeElem.appendChild( document.createElement( "ol" ) );
68                         fakeElem.appendChild( document.createElement( "ol" ) );
69                         QUnit.id = function(){
70                                 return fakeElem;
71                         }
72                 },
73                 teardown: function(){
74                         QUnit.id = id;
75                 }
76         };
77 })());
78
79 test( "test expansions are hidden", function(){
80         QUnit.testDone();
81         equal( this.fakeElem.children[0].style.display, "none", "first ol display is none" );
82         equal( this.fakeElem.children[1].style.display, "none", "second ol display is none" );
83 });
84
85 test( "non-ol elements aren't hidden", function(){
86         this.fakeElem.appendChild( document.createElement( "span" ) );
87
88         QUnit.testDone();
89         notEqual( this.fakeElem.children[2].style.display, "none", "first ol display is none" );
90 });
91
92 module( "runSuite tests", (function(){
93         var getElementsByTagName = document.getElementsByTagName,
94                 createElement = document.createElement,
95                 runSuite = QUnit.runSuite;
96
97         return {
98                 setup: function(){
99                         //proxy getElementsByTagName and createElement
100                         var setAttributeCall = this.setAttributeCall = {},
101                                 appendChildCall = this.appendChildCall = {called: 0},
102                                 iframeLoad = this.iframeLoad = {},
103                                 iframeQUnitObject = this.iframeQUnitObject = {},
104                                 fakeElement = {
105                                         appendChild: function(){appendChildCall.called++},
106                                         setAttribute: function(){setAttributeCall.args = arguments},
107                                         addEventListener: function( type, callback ){iframeLoad.callback = callback;},
108                                         contentWindow: {QUnit: iframeQUnitObject},
109                                         className: "",
110                                 };
111
112                         document.getElementsByTagName = function(){
113                                 return [fakeElement];
114                         };
115                         document.createElement = function(){
116                                 return fakeElement;
117                         }
118
119                 },
120                 teardown: function(){
121                         document.getElementsByTagName = getElementsByTagName;
122                         document.createElement = createElement;
123                         //must restore even though we didn't proxy; the runner overwrites upon first call
124                         QUnit.runSuite = runSuite;
125                 }
126         };
127 })());
128
129 test( "runSuite different after first run", function(){
130         var before = QUnit.runSuite,
131                 after;
132         QUnit.runSuite();
133         after = QUnit.runSuite;
134         notEqual( before, after, "runSuite changed after initial run" );
135 });
136
137 test( "iframe only created once", function(){
138         QUnit.runSuite();
139         equal( this.appendChildCall.called, 1, "append child called once" );
140         QUnit.runSuite();
141         equal( this.appendChildCall.called, 1, "append child only ever called once" );
142 });
143
144 test( "iframe's QUnit object is modified when iframe source loads", function(){
145         var before = this.iframeQUnitObject,
146                 after;
147         QUnit.runSuite();
148         this.iframeLoad.callback();
149         notEqual( before, after, "iframe's qunit object is modified upon load");
150 });
151
152 test( "iframe src set to suite passed", function(){
153         var pages = ["testing.html", "subsuiteRunner.html"];
154         QUnit.runSuite( pages[0] );
155         equal( this.setAttributeCall.args[0], "src", "src attribute set" );
156         equal( this.setAttributeCall.args[1], pages[0], "src attribute set" );
157         QUnit.runSuite( pages[1] );
158         equal( this.setAttributeCall.args[1], pages[1], "src attribute set" );
159 });

Hosting is provided AltSPAHow to use Git
Please direct any questions on jabber alex.wolf@jabber.ru

Valid HTML 4.0 Transitional Valid CSS!

Designer Alexander Wolf