Skip to content

Commit

Permalink
Export the users (getCurrentUser) method as part of an object so that…
Browse files Browse the repository at this point in the history
… we can stub them as part of the TypeScript 3.9.2+ update

It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue:

microsoft/TypeScript#38568
sinonjs/sinon#562

The test in App.test.tsx was failing when it tried to get the callCount for a stub for a free-standing function getCurrentUser, and currently, my package-lock.json has 3.9.5, so that appears to be why. My fix was to use an object where the functions become methods instead.
  • Loading branch information
natalynyu committed Aug 3, 2020
1 parent ef26580 commit e1d0617
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/client/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ import request, { AxiosPromise } from './request';
* Get the currently authenticated user
*/

export const getCurrentUser = (): AxiosPromise<UserResponse> => request.get('/api/users/current');
const getCurrentUser = (): AxiosPromise<UserResponse> => request.get('/api/users/current');

/**
* Export the methods as part of an object so that they are stubbable.
* See: https://github.com/sinonjs/sinon/issues/562
*/
export const UserAPI = {
getCurrentUser,
};

0 comments on commit e1d0617

Please sign in to comment.