Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

Commit aeef939

Browse files
fix: load mock values on init for mockUseKeyedState
1 parent d77d9aa commit aeef939

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/testUtils/mockUseKeyedState.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ export class MockUseKeyedState {
122122
* @param {any} val - new value to be returned by the useState call.
123123
*/
124124
mockVal(mockKey, val) {
125-
this.hookSpy.mockImplementationOnce((key) => {
125+
this.hookSpy.mockImplementationOnce((key, newVal) => {
126126
if (key === mockKey) {
127+
this.values[key] = val;
128+
this.initValues[key] = newVal;
127129
return [val, this.setState[key]];
128130
}
129131
return this.mockHook(key);
@@ -136,8 +138,10 @@ export class MockUseKeyedState {
136138
* @param {object} mapping - { <stateKey>: <val to return> }
137139
*/
138140
mockVals(mapping) {
139-
this.hookSpy.mockImplementation((key) => {
141+
this.hookSpy.mockImplementation((key, val) => {
140142
if (mapping[key]) {
143+
this.values[key] = mapping[key];
144+
this.initValues[key] = val;
141145
return [mapping[key], this.setState[key]];
142146
}
143147
return this.mockHook(key);

0 commit comments

Comments
 (0)