Search code examples
angularmicrosoft-teamssinon

Microsoft Teams Angular application, Sinon Stub `microsoftTeams.authentication.notifySuccess`


I'm currently working on a Microsoft Teams Angular application, and testing the Microsoft Teams library.

I'm trying the test the call below with SinonJS but have had no luck. Is there an efficient way to test that microsoft.authentication.notifySuccess was called with the param of token?

microsoftTeams.initialize(() =>
  microsoftTeams.authentication.notifySuccess({token} as any)
);

I'm looking for something like

 sinon.assert.calledWith(microsoftTeams.authentication.notifySuccess as sinon.SinonStub, {token});

Thanks in advance :D


Solution

  • // This is the bit I was missing, we need to tell sinon to take in a 
    // function/callback and immediately call it.
    sandbox.stub(microsoftTeams, 'initialize').callsFake((callback) => callback());
    sandbox.stub(microsoftTeams.authentication, 'notifySuccess');
    
    // Run code and assert
    sinon.assert.calledWith(microsoftTeams.authentication.notifySuccess as sinon.SinonStub, {token})