Skip to content

Commit d206d2c

Browse files
committed
Fix App callCount test by no longer stubbing free-standing function getCurrentUser due to version change
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.
1 parent 73bda7d commit d206d2c

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/client/components/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
PageTitle,
3333
Link,
3434
} from 'mark-one';
35-
import { getCurrentUser } from 'client/api';
35+
import { UserAPI } from 'client/api';
3636
import { UserResponse } from 'common/dto/users/userResponse.dto';
3737
import { MetadataContext } from 'client/context/MetadataContext';
3838
import { getMetadata } from 'client/api/metadata';
@@ -76,7 +76,7 @@ const ColdApp: SFC = (): ReactElement => {
7676
*/
7777

7878
useEffect((): void => {
79-
getCurrentUser()
79+
UserAPI.getCurrentUser()
8080
.then(({ data: user }): UserResponse => {
8181
setUser(user);
8282
return user;

src/client/components/__tests__/App.test.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import { stub, SinonStub } from 'sinon';
1010
import { AxiosResponse } from 'axios';
1111
import { UserResponse } from 'common/dto/users/userResponse.dto';
1212
import * as dummy from 'testData';
13-
import * as api from 'client/api';
13+
import { UserAPI } from 'client/api';
1414
import { MarkOneTheme } from 'mark-one';
1515
import { App } from '../App';
1616

1717
describe('App', function () {
1818
let apiStub: SinonStub;
1919
beforeEach(function () {
20-
apiStub = stub(api, 'getCurrentUser');
20+
apiStub = stub(UserAPI, 'getCurrentUser');
2121
apiStub.resolves({
2222
data: dummy.regularUser,
2323
} as AxiosResponse<UserResponse>);
@@ -154,9 +154,10 @@ describe('App', function () {
154154
<App />
155155
</MemoryRouter>
156156
);
157-
strictEqual(apiStub.callCount, 1);
158157
const { fullName } = dummy.regularUser;
159-
return waitForElement(() => getByText(fullName, { exact: false }));
158+
await waitForElement(() => getByText(fullName, { exact: false }));
159+
strictEqual(apiStub.callCount, 1);
160+
return getByText(fullName, { exact: false });
160161
});
161162
});
162163
context('When userFetch fails', function () {

0 commit comments

Comments
 (0)