rendererasserts.js 1.9 KB

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