Debian Codegraph @

closure-library/closure/goog/testing/ui/rendererasserts.js

raw
1 // Copyright 2009 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 /**
16 * @fileoverview Additional asserts for testing ControlRenderers.
17 *
18 * @author [email protected] (Martin Kretzschmar)
19 */
20
21 goog.setTestOnly('goog.testing.ui.rendererasserts');
22 goog.provide('goog.testing.ui.rendererasserts');
23
24 goog.require('goog.testing.asserts');
25 goog.require('goog.ui.ControlRenderer');
26
27
28 /**
29 * Assert that a control renderer constructor doesn't call getCssClass.
30 *
31 * @param {function(new:goog.ui.ControlRenderer)} rendererClassUnderTest The
32 * renderer constructor to test.
33 */
34 goog.testing.ui.rendererasserts.assertNoGetCssClassCallsInConstructor =
35 function(rendererClassUnderTest) {
36 var getCssClassCalls = 0;
37
38 /**
39 * @constructor
40 * @extends {goog.ui.ControlRenderer}
41 * @final
42 */
43 function TestControlRenderer() { rendererClassUnderTest.call(this); }
44 goog.inherits(TestControlRenderer, rendererClassUnderTest);
45
46 /** @override */
47 TestControlRenderer.prototype.getCssClass = function() {
48 getCssClassCalls++;
49 return TestControlRenderer.superClass_.getCssClass.call(this);
50 };
51
52 // Looking for the side-effects caused by the construction here:
53 new TestControlRenderer();
54
55 assertEquals(
56 'Constructors should not call getCssClass, ' +
57 'getCustomRenderer must be able to override it post construction.',
58 0, getCssClassCalls);
59 };