Skip to content

Commit 4f95ddd

Browse files
committed
Update tests to test a little more
1 parent 643e294 commit 4f95ddd

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

packages-exp/auth-exp/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@
3030
},
3131
"dependencies": {
3232
"@firebase/util": "^0.2.44",
33-
"mocha": "^7.1.1",
3433
"tslib": "1.11.1"
3534
},
3635
"license": "Apache-2.0",
3736
"devDependencies": {
3837
"rollup": "1.32.1",
3938
"rollup-plugin-json": "4.0.0",
4039
"rollup-plugin-replace": "2.2.0",
41-
"rollup-plugin-typescript2": "0.26.0",
42-
"typescript": "3.8.3"
40+
"rollup-plugin-typescript2": "0.26.0"
4341
},
4442
"repository": {
4543
"directory": "packages-exp/auth-exp",

packages-exp/auth-exp/test/api/authentication/sign_up.test.ts renamed to packages-exp/auth-exp/src/api/authentication/sign_up.test.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as mockFetch from '../../mock_fetch';
19-
import { signUp, SignUpRequest } from '../../../src/api/authentication/sign_up';
20-
import { expect } from 'chai';
21-
import { Endpoint } from '../../../src/api';
22-
import { ServerError } from '../../../src/api/errors';
23-
import { mockEndpoint, mockAuth } from '../helper';
18+
import { expect, use } from 'chai';
19+
import * as chaiAsPromised from 'chai-as-promised';
20+
import { signUp, SignUpRequest } from './sign_up';
21+
import { Endpoint } from '..';
22+
import { ServerError } from '../errors';
23+
import { FirebaseError } from '@firebase/util';
24+
import * as mockFetch from '../../../test/mock_fetch';
25+
import { mockEndpoint, mockAuth } from '../../../test/api/helper';
26+
27+
use(chaiAsPromised);
2428

2529
describe('signUp', () => {
2630
const request: SignUpRequest = {
@@ -41,9 +45,9 @@ describe('signUp', () => {
4145
const response = await signUp(mockAuth, request);
4246
expect(response.displayName).to.eq('my-name');
4347
expect(response.email).to.eq('[email protected]');
44-
expect(mock.calls[0]).to.eql({
45-
request
46-
});
48+
expect(mock.calls[0].request).to.eql(request);
49+
expect(mock.calls[0].method).to.eq('POST');
50+
expect(mock.calls[0].headers).to.eql({ 'Content-Type': 'application/json' });
4751
});
4852

4953
it('should handle errors', async () => {
@@ -63,16 +67,9 @@ describe('signUp', () => {
6367
400
6468
);
6569

66-
try {
67-
await signUp(mockAuth, request);
68-
} catch (e) {
69-
expect(e.name).to.eq('FirebaseError');
70-
expect(e.message).to.eq(
71-
'Firebase: The email address is already in use by another account. (auth/email-already-in-use).'
72-
);
73-
expect(mock.calls[0]).to.eql({
74-
request
75-
});
76-
}
70+
await expect(signUp(mockAuth, request)).to.be.rejectedWith(FirebaseError, 'Firebase: The email address is already in use by another account. (auth/email-already-in-use).');
71+
expect(mock.calls[0].request).to.eql(
72+
request
73+
);
7774
});
7875
});

packages-exp/auth-exp/test/core/errors.test.ts renamed to packages-exp/auth-exp/src/core/errors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { expect } from 'chai';
19-
import { AUTH_ERROR_FACTORY, AuthErrorCode } from '../../src/core/errors';
19+
import { AUTH_ERROR_FACTORY, AuthErrorCode } from './errors';
2020

2121
describe('AUTH_ERROR_FACTORY', () => {
2222
it('should create an Auth namespaced FirebaseError', () => {

packages-exp/auth-exp/test/mock_fetch.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { stub, SinonStub } from 'sinon';
1919

2020
export interface Call {
2121
request?: object;
22+
method?: string;
23+
headers?: HeadersInit;
2224
}
2325

2426
export interface Route {
@@ -44,7 +46,9 @@ const fakeFetch: typeof fetch = (input: RequestInfo, request?: RequestInit) => {
4446
const { response, status, calls } = routes.get(input)!;
4547

4648
calls.push({
47-
request: request?.body ? JSON.parse(request.body as string) : undefined
49+
request: request?.body ? JSON.parse(request.body as string) : undefined,
50+
method: request?.method,
51+
headers: request?.headers
4852
});
4953

5054
const blob = new Blob([JSON.stringify(response)]);

0 commit comments

Comments
 (0)