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:
goog.testing.PropertyReplacer |
![]()
Deletes the key from the object while saving its original value.
|
code » | ||||
![]()
Changes an existing value in an object to another one of the same type while
saving its original state. The advantage of
replace over #set
is that replace protects against typos and erroneously passing tests
after some members have been renamed during a refactoring.
Arguments:
|
code » | ||||
![]()
Resets all changes made by goog.testing.PropertyReplacer.prototype.set.
|
code » | ||||
![]()
Adds or changes a value in an object while saving its original state.
|
code » | ||||
![]()
Builds an object structure for the provided namespace path. Doesn't
overwrite those prefixes of the path that are already objects or functions.
Arguments:
|
code » |
![]()
Stores the values changed by the set() method in chronological order.
Its items are objects with 3 fields: 'object', 'key', 'value'. The
original value for the given key in the given object is stored under the
'value' key.
|
Code » |
![]()
Deletes a key from an object. Sets it to undefined or empty string if the
delete failed.
|
code » | |
Tells if the given key exists in the object. Ignores inherited fields.
|
code » |
![]()
Indicates that a key didn't exist before having been set by the set() method.
|
Code » |