Skip to content

Commit

Permalink
Merge pull request #15 from openedx/bw/shallow-logging
Browse files Browse the repository at this point in the history
fix: load mock values on init for mockUseKeyedState
  • Loading branch information
muselesscreator authored Jul 6, 2023
2 parents 9951698 + aeef939 commit fa80cf9
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 fa80cf9

Please sign in to comment.