Skip to content

Commit

Permalink
fix: load mock values on init for mockUseKeyedState
Browse files Browse the repository at this point in the history
  • Loading branch information
muselesscreator committed Jul 6, 2023
1 parent d77d9aa commit aeef939
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/testUtils/mockUseKeyedState.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ export class MockUseKeyedState {
* @param {any} val - new value to be returned by the useState call.
*/
mockVal(mockKey, val) {
this.hookSpy.mockImplementationOnce((key) => {
this.hookSpy.mockImplementationOnce((key, newVal) => {
if (key === mockKey) {
this.values[key] = val;
this.initValues[key] = newVal;
return [val, this.setState[key]];
}
return this.mockHook(key);
Expand All @@ -136,8 +138,10 @@ export class MockUseKeyedState {
* @param {object} mapping - { <stateKey>: <val to return> }
*/
mockVals(mapping) {
this.hookSpy.mockImplementation((key) => {
this.hookSpy.mockImplementation((key, val) => {
if (mapping[key]) {
this.values[key] = mapping[key];
this.initValues[key] = val;
return [mapping[key], this.setState[key]];
}
return this.mockHook(key);
Expand Down

0 comments on commit aeef939

Please sign in to comment.