rendererasserts_test.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. goog.provide('goog.testing.ui.rendererassertsTest');
  15. goog.setTestOnly('goog.testing.ui.rendererassertsTest');
  16. goog.require('goog.testing.TestCase');
  17. goog.require('goog.testing.asserts');
  18. goog.require('goog.testing.jsunit');
  19. goog.require('goog.testing.ui.rendererasserts');
  20. goog.require('goog.ui.ControlRenderer');
  21. function setUp() {
  22. // TODO(b/25875505): Fix unreported assertions (go/failonunreportedasserts).
  23. goog.testing.TestCase.getActiveTestCase().failOnUnreportedAsserts = false;
  24. }
  25. function testSuccess() {
  26. function GoodRenderer() {}
  27. goog.testing.ui.rendererasserts.assertNoGetCssClassCallsInConstructor(
  28. GoodRenderer);
  29. }
  30. function testFailure() {
  31. function BadRenderer() {
  32. goog.ui.ControlRenderer.call(this);
  33. this.myClass = this.getCssClass();
  34. }
  35. goog.inherits(BadRenderer, goog.ui.ControlRenderer);
  36. var ex = assertThrows(
  37. 'Expected assertNoGetCssClassCallsInConstructor to fail.', function() {
  38. goog.testing.ui.rendererasserts.assertNoGetCssClassCallsInConstructor(
  39. BadRenderer);
  40. });
  41. assertTrue(
  42. 'Expected assertNoGetCssClassCallsInConstructor to throw a' +
  43. ' jsunit exception',
  44. ex.isJsUnitException);
  45. assertContains('getCssClass', ex.message);
  46. }