Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do no reset every mock, when calling resetSpyMsal() #22

Open
anotherHoffmann opened this issue Jan 24, 2024 · 3 comments
Open

Do no reset every mock, when calling resetSpyMsal() #22

anotherHoffmann opened this issue Jan 24, 2024 · 3 comments

Comments

@anotherHoffmann
Copy link

When calling resetSpyMsal(), every mock of the test-runner is reset, which causes issues when one is also mocking other functionality than MSAL.

resetSpyMsal() {
    this._testRunner.resetAllMocks();
    this.accounts = [];
    this.activeAccount = null;
    this._eventCallbacks = [];
}

Is there a possibility to only reset mocks related to MSAL?

@Mimetis
Copy link
Owner

Mimetis commented Jan 25, 2024

No Idea, maybe some options in the testRunner ?

@evocateur
Copy link

Any time this._testRunner.spyOn() is called, the spy return value should be stored in some sort of instance cache, then resetSpyMsal() loops through this cache and calls .mockReset() on each spy present. Many calls to spyOn() are already cached in "private" instance properties, so the bulk of the work would be figuring out the best caching approach (this._spies = new Map<string, jest.Spied<unknown>>(), a private _createSpy(obj, methodName): jest.Spied<typeof obj[methodName]> method that could do the Map bookkeeping, _getSpy(methodName): jest.Spied<unknown> to simplify retrieval inside various assertions, and so on).

@Mimetis
Copy link
Owner

Mimetis commented Feb 9, 2024

Sounds interesting
Thanks a lot @evocateur
Are you motivated enough to make a quick PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants