propertyreplacer.js
No description.

File Location

/goog/testing/propertyreplacer.js

Classes

goog.testing.PropertyReplacer
Helper class for stubbing out variables and object properties for unit tests. This class can change the value of some variables before running the test cases, and to reset them in the tearDown phase. See googletest.StubOutForTesting as an analogy in Python: http://protobuf.googlecode.com/svn/trunk/python/stubout.py Example usage:
var stubs = new goog.testing.PropertyReplacer();

function setUp() {
  // Mock functions used in all test cases.
  stubs.set(Math, 'random', function() {
    return 4;  // Chosen by fair dice roll. Guaranteed to be random.
  });
}

function tearDown() {
  stubs.reset();
}

function testThreeDice() {
  // Mock a constant used only in this test case.
  stubs.set(goog.global, 'DICE_COUNT', 3);
  assertEquals(12, rollAllDice());
}
Constraints on altered objects:
  • DOM subclasses aren't supported.
  • The value of the objects' constructor property must either be equal to the real constructor or kept untouched.

Public Protected Private

Global Functions

goog.testing.PropertyReplacer.deleteKey_(objkey)
Deletes a key from an object. Sets it to undefined or empty string if the delete failed.
Arguments:
obj : Object | Function
The object or function to delete a key from.
key : string
The key to delete.
code »
goog.testing.PropertyReplacer.hasKey_(objkey) boolean
Tells if the given key exists in the object. Ignores inherited fields.
Arguments:
obj : Object | Function
The JavaScript or native object or function whose key is to be checked.
key : string
The key to check.
Returns: boolean  Whether the object has the key as own key.
code »

Directory testing

File Reference