| 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 This module simplifies testing code which uses stateful |
| 17 |
* singletons. {@code goog.testing.singleton.reset} resets all instances, so |
| 18 |
* next time when {@code getInstance} is called, a new instance is created. |
| 19 |
* It's recommended to reset the singletons in {@code tearDown} to prevent |
| 20 |
* interference between subsequent tests. |
| 21 |
* |
| 22 |
* The {@code goog.testing.singleton} functions expect that the goog.DEBUG flag |
| 23 |
* is enabled, and the tests are either uncompiled or compiled without renaming. |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
goog.setTestOnly('goog.testing.singleton'); |
| 28 |
goog.provide('goog.testing.singleton'); |
| 29 |
|
| 30 |
|
| 31 |
/** |
| 32 |
* Deletes all singleton instances, so {@code getInstance} will return a new |
| 33 |
* instance on next call. |
| 34 |
*/ |
| 35 |
goog.testing.singleton.reset = function() { |
| 36 |
var singletons = goog.getObjectByName('goog.instantiatedSingletons_'); |
| 37 |
var ctor; |
| 38 |
while (ctor = singletons.pop()) { |
| 39 |
delete ctor.instance_; |
| 40 |
} |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
/** |
| 45 |
* @deprecated Please use {@code goog.addSingletonGetter}. |
| 46 |
*/ |
| 47 |
goog.testing.singleton.addSingletonGetter = goog.addSingletonGetter; |