You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceCollaborator{collaborate(): void;}classMyClass{privatecollaborator: Collaborator;constructor(collaborator: Collaborator){this.collaborator=collaborator;}run(): void{this.collaborator.collaborate();}}test('example of a spying an interaction',()=>{constcollaborator=mock<Collaborator>();constmyClass=newMyClass(instance(collaborator));myClass.run();verify(collaborator.collaborate()).once();});
Example of stubbing an interaction
interfaceCollaborator{collaborate(): string;}classMyClass{privatecollaborator: Collaborator;constructor(collaborator: Collaborator){this.collaborator=collaborator;}run(): void{returnthis.collaborator.collaborate();}}test('example of a stubbing an interaction',()=>{constcollaboratorResponse="some response";constcollaborator=mock<Collaborator>();when(collaborator.collaborate()).thenReturn(collaboratorResponse);constmyClass=newMyClass(instance(collaborator));constresult=myClass.run();expect(result).toBe(collaboratorResponse);});