Debian Codegraph @

closure-library/closure/goog/testing/asynctestcase_test.js

raw
1 // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.testing.AsyncTestCaseTest');
16 goog.setTestOnly('goog.testing.AsyncTestCaseTest');
17
18 goog.require('goog.debug.Error');
19 goog.require('goog.testing.AsyncTestCase');
20 goog.require('goog.testing.asserts');
21 goog.require('goog.testing.jsunit');
22
23 function testControlBreakingExceptionThrown() {
24 var asyncTestCase = new goog.testing.AsyncTestCase();
25
26 // doAsyncError with no message.
27 try {
28 asyncTestCase.doAsyncError();
29 } catch (e) {
30 assertTrue(e.isControlBreakingException);
31 assertEquals('', e.message);
32 }
33
34 // doAsyncError with string.
35 var errorMessage1 = 'Error message 1';
36 try {
37 asyncTestCase.doAsyncError(errorMessage1);
38 } catch (e) {
39 assertTrue(e.isControlBreakingException);
40 assertEquals(errorMessage1, e.message);
41 }
42
43 // doAsyncError with error.
44 var errorMessage2 = 'Error message 2';
45 try {
46 var error = new goog.debug.Error(errorMessage2);
47 asyncTestCase.doAsyncError(error);
48 } catch (e) {
49 assertTrue(e.isControlBreakingException);
50 assertEquals(errorMessage2, e.message);
51 }
52 }
53
54 function testMaybeFailTestEarly() {
55 var message = 'Error in setUpPage().';
56 var asyncTestCase = new goog.testing.AsyncTestCase();
57 asyncTestCase.setUpPage = function() {
58 throw new Error(message);
59 };
60 asyncTestCase.addNewTest('test', function() { assertTrue(true); });
61 asyncTestCase.runTests();
62 window.setTimeout(function() {
63 assertFalse(asyncTestCase.isSuccess());
64 var errors = asyncTestCase.getResult().errors;
65 assertEquals(1, errors.length);
66 assertEquals(message, errors[0].message);
67 }, asyncTestCase.stepTimeout * 2);
68 }