|
0
|
1 |
|
|
|
2 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|
|
3 |
<html> |
|
|
4 |
<head> |
|
|
5 |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|
|
6 |
<title>Advanced Test Options</title> |
|
|
7 |
|
|
|
8 |
<style type="text/css"> |
|
|
9 |
/*margin and padding on body element |
|
|
10 |
can introduce errors in determining |
|
|
11 |
element position and are not recommended; |
|
|
12 |
we turn them off as a foundation for YUI |
|
|
13 |
CSS treatments. */ |
|
|
14 |
body { |
|
|
15 |
margin:0; |
|
|
16 |
padding:0; |
|
|
17 |
} |
|
|
18 |
</style> |
|
|
19 |
|
|
|
20 |
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" /> |
|
|
21 |
<script type="text/javascript" src="../../build/yui/yui-min.js"></script> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<!--begin custom header content for this example--> |
|
|
25 |
<style type="text/css"> |
|
|
26 |
#testLogger { |
|
|
27 |
margin-bottom: 1em; |
|
|
28 |
} |
|
|
29 |
|
|
|
30 |
#testLogger .yui-console .yui-console-title { |
|
|
31 |
border: 0 none; |
|
|
32 |
color: #000; |
|
|
33 |
font-size: 13px; |
|
|
34 |
font-weight: bold; |
|
|
35 |
margin: 0; |
|
|
36 |
text-transform: none; |
|
|
37 |
} |
|
|
38 |
#testLogger .yui-console .yui-console-entry-meta { |
|
|
39 |
margin: 0; |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
.yui-skin-sam .yui-console-entry-pass .yui-console-entry-cat { |
|
|
43 |
background: #070; |
|
|
44 |
color: #fff; |
|
|
45 |
} |
|
|
46 |
.yui-skin-sam .yui-console-entry-fail .yui-console-entry-cat { |
|
|
47 |
background: #700; |
|
|
48 |
color: #fff; |
|
|
49 |
} |
|
|
50 |
</style> |
|
|
51 |
|
|
|
52 |
<!--end custom header content for this example--> |
|
|
53 |
|
|
|
54 |
</head> |
|
|
55 |
|
|
|
56 |
<body class=" yui-skin-sam"> |
|
|
57 |
|
|
|
58 |
<h1>Advanced Test Options</h1> |
|
|
59 |
|
|
|
60 |
<div class="exampleIntro"> |
|
|
61 |
<p>This example shows how to use advanced test options, which allow you to specify additional information about how a test should be run. |
|
|
62 |
Each <a href="/yui/test/#testcase"><code>TestCase</code></a> can specify up to three different options for tests, |
|
|
63 |
including tests that should be ignored, tests that should throw an error, and tests that should fail.</p> |
|
|
64 |
</div> |
|
|
65 |
|
|
|
66 |
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
67 |
|
|
|
68 |
<div id="testLogger"></div> |
|
|
69 |
<script type="text/javascript"> |
|
|
70 |
YUI({base:"../../build/", timeout: 10000}).use("node", "console", "test",function (Y) { |
|
|
71 |
|
|
|
72 |
Y.namespace("example.test"); |
|
|
73 |
|
|
|
74 |
Y.example.test.AdvancedOptionsTestCase = new Y.Test.Case({ |
|
|
75 |
|
|
|
76 |
//the name of the test case - if not provided, one is automatically generated |
|
|
77 |
name: "Advanced Options Tests", |
|
|
78 |
|
|
|
79 |
/* |
|
|
80 |
* Specifies tests that "should" be doing something other than the expected. |
|
|
81 |
*/ |
|
|
82 |
_should: { |
|
|
83 |
|
|
|
84 |
/* |
|
|
85 |
* Tests listed in here should fail, meaning that if they fail, the test |
|
|
86 |
* has passed. This is used mostly for YuiTest to test itself, but may |
|
|
87 |
* be helpful in other cases. |
|
|
88 |
*/ |
|
|
89 |
fail: { |
|
|
90 |
|
|
|
91 |
//the test named "testFail" should fail |
|
|
92 |
testFail: true |
|
|
93 |
|
|
|
94 |
}, |
|
|
95 |
|
|
|
96 |
/* |
|
|
97 |
* Tests listed here should throw an error of some sort. If they throw an |
|
|
98 |
* error, then they are considered to have passed. |
|
|
99 |
*/ |
|
|
100 |
error: { |
|
|
101 |
|
|
|
102 |
/* |
|
|
103 |
* You can specify "true" for each test, in which case any error will |
|
|
104 |
* cause the test to pass. |
|
|
105 |
*/ |
|
|
106 |
testGenericError: true, |
|
|
107 |
|
|
|
108 |
/* |
|
|
109 |
* You can specify an error message, in which case the test passes only |
|
|
110 |
* if the error thrown matches the given message. |
|
|
111 |
*/ |
|
|
112 |
testStringError: "I'm a specific error message.", |
|
|
113 |
testStringError2: "I'm a specific error message.", |
|
|
114 |
|
|
|
115 |
/* |
|
|
116 |
* You can also specify an error object, in which case the test passes only |
|
|
117 |
* if the error thrown is on the same type and has the same message. |
|
|
118 |
*/ |
|
|
119 |
testObjectError: new TypeError("Number expected."), |
|
|
120 |
testObjectError2: new TypeError("Number expected."), |
|
|
121 |
testObjectError3: new TypeError("Number expected.") |
|
|
122 |
|
|
|
123 |
}, |
|
|
124 |
|
|
|
125 |
/* |
|
|
126 |
* Tests listed here should be ignored when the test case is run. For these tests, |
|
|
127 |
* setUp() and tearDown() are not called. |
|
|
128 |
*/ |
|
|
129 |
ignore : { |
|
|
130 |
|
|
|
131 |
testIgnore: true |
|
|
132 |
|
|
|
133 |
} |
|
|
134 |
}, |
|
|
135 |
|
|
|
136 |
//------------------------------------------------------------------------- |
|
|
137 |
// Basic tests - all method names must begin with "test" |
|
|
138 |
//------------------------------------------------------------------------- |
|
|
139 |
|
|
|
140 |
testFail : function() { |
|
|
141 |
|
|
|
142 |
//force a failure - but since this test "should" fail, it will pass |
|
|
143 |
Y.Assert.fail("Something bad happened."); |
|
|
144 |
|
|
|
145 |
}, |
|
|
146 |
|
|
|
147 |
testGenericError : function() { |
|
|
148 |
throw new Error("Generic error"); |
|
|
149 |
}, |
|
|
150 |
|
|
|
151 |
testStringError : function() { |
|
|
152 |
|
|
|
153 |
//throw a specific error message - this will pass because it "should" happen |
|
|
154 |
throw new Error("I'm a specific error message."); |
|
|
155 |
}, |
|
|
156 |
|
|
|
157 |
testStringError2 : function() { |
|
|
158 |
|
|
|
159 |
//throw a specific error message - this will fail because the message isn't expected |
|
|
160 |
throw new Error("I'm a specific error message, but a wrong one."); |
|
|
161 |
}, |
|
|
162 |
|
|
|
163 |
testObjectError : function() { |
|
|
164 |
|
|
|
165 |
//throw a specific error and message - this will pass because it "should" happen |
|
|
166 |
throw new TypeError("Number expected."); |
|
|
167 |
}, |
|
|
168 |
|
|
|
169 |
testObjectError2 : function() { |
|
|
170 |
|
|
|
171 |
//throw a specific error and message - this will fail because the type doesn't match |
|
|
172 |
throw new Error("Number expected."); |
|
|
173 |
}, |
|
|
174 |
|
|
|
175 |
testObjectError3 : function() { |
|
|
176 |
|
|
|
177 |
//throw a specific error and message - this will fail because the message doesn't match |
|
|
178 |
throw new TypeError("String expected."); |
|
|
179 |
}, |
|
|
180 |
|
|
|
181 |
testIgnore : function () { |
|
|
182 |
alert("You'll never see this."); |
|
|
183 |
} |
|
|
184 |
|
|
|
185 |
}); |
|
|
186 |
|
|
|
187 |
|
|
|
188 |
//create the console |
|
|
189 |
var r = new Y.Console({ |
|
|
190 |
newestOnTop : false, |
|
|
191 |
style: 'block' // to anchor in the example content |
|
|
192 |
}); |
|
|
193 |
|
|
|
194 |
r.render('#testLogger'); |
|
|
195 |
|
|
|
196 |
Y.Test.Runner.add(Y.example.test.AdvancedOptionsTestCase); |
|
|
197 |
|
|
|
198 |
//run the tests |
|
|
199 |
Y.Test.Runner.run(); |
|
|
200 |
}); |
|
|
201 |
|
|
|
202 |
</script> |
|
|
203 |
|
|
|
204 |
<!--END SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
205 |
|
|
|
206 |
</body> |
|
|
207 |
</html> |