summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/methods
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2021-08-25 22:53:46 -0700
committerMatthew Miller <matthew@millerti.me>2021-08-25 22:55:20 -0700
commit8a33d15d43e18659fe8c63de62202b8dcf29fb01 (patch)
treef084378b1bafe9182e4aa3fd6ce56548cea96615 /packages/browser/src/methods
parent69a3b97c68badb2b9ea9b6f1589a45e47c7a4030 (diff)
Update jest tests
Diffstat (limited to 'packages/browser/src/methods')
-rw-r--r--packages/browser/src/methods/startAuthentication.test.ts36
-rw-r--r--packages/browser/src/methods/startRegistration.test.ts32
2 files changed, 17 insertions, 51 deletions
diff --git a/packages/browser/src/methods/startAuthentication.test.ts b/packages/browser/src/methods/startAuthentication.test.ts
index 5e74789..2e455d6 100644
--- a/packages/browser/src/methods/startAuthentication.test.ts
+++ b/packages/browser/src/methods/startAuthentication.test.ts
@@ -60,7 +60,7 @@ afterEach(() => {
mockSupportsWebauthn.mockReset();
});
-test('should convert options before passing to navigator.credentials.get(...)', async done => {
+test('should convert options before passing to navigator.credentials.get(...)', async () => {
await startAuthentication(goodOpts1);
const argsPublicKey = mockNavigatorGet.mock.calls[0][0].publicKey;
@@ -70,8 +70,6 @@ test('should convert options before passing to navigator.credentials.get(...)',
// Make sure the credential ID is an ArrayBuffer with a length of 64
expect(credId instanceof ArrayBuffer).toEqual(true);
expect(credId.byteLength).toEqual(64);
-
- done();
});
test('should support optional allowCredential', async () => {
@@ -92,7 +90,7 @@ test('should convert allow allowCredential to undefined when empty', async () =>
expect(mockNavigatorGet.mock.calls[0][0].allowCredentials).toEqual(undefined);
});
-test('should return base64url-encoded response values', async done => {
+test('should return base64url-encoded response values', async () => {
mockNavigatorGet.mockImplementation((): Promise<AuthenticationCredential> => {
return new Promise(resolve => {
resolve({
@@ -117,21 +115,17 @@ test('should return base64url-encoded response values', async done => {
expect(response.response.clientDataJSON).toEqual('bW9ja0NsaWVudERhdGFKU09O');
expect(response.response.signature).toEqual('bW9ja1NpZ25hdHVyZQ');
expect(response.response.userHandle).toEqual('mockUserHandle');
-
- done();
});
-test("should throw error if WebAuthn isn't supported", async done => {
+test("should throw error if WebAuthn isn't supported", async () => {
mockSupportsWebauthn.mockReturnValue(false);
await expect(startAuthentication(goodOpts1)).rejects.toThrow(
'WebAuthn is not supported in this browser',
);
-
- done();
});
-test('should throw error if assertion is cancelled for some reason', async done => {
+test('should throw error if assertion is cancelled for some reason', async () => {
mockNavigatorGet.mockImplementation((): Promise<null> => {
return new Promise(resolve => {
resolve(null);
@@ -139,11 +133,9 @@ test('should throw error if assertion is cancelled for some reason', async done
});
await expect(startAuthentication(goodOpts1)).rejects.toThrow('Authentication was not completed');
-
- done();
});
-test('should handle UTF-8 challenges', async done => {
+test('should handle UTF-8 challenges', async () => {
await startAuthentication(goodOpts2UTF8);
const argsPublicKey = mockNavigatorGet.mock.calls[0][0].publicKey;
@@ -153,11 +145,9 @@ test('should handle UTF-8 challenges', async done => {
227, 130, 132, 227, 130, 140, 227, 130, 132, 227, 130, 140, 227, 129, 160, 227, 129, 156,
]),
);
-
- done();
});
-test('should send extensions to authenticator if present in options', async done => {
+test('should send extensions to authenticator if present in options', async () => {
const extensions: AuthenticationExtensionsClientInputs = {
credProps: true,
appid: 'appidHere',
@@ -173,21 +163,17 @@ test('should send extensions to authenticator if present in options', async done
const argsExtensions = mockNavigatorGet.mock.calls[0][0].publicKey.extensions;
expect(argsExtensions).toEqual(extensions);
-
- done();
});
-test('should not set any extensions if not present in options', async done => {
+test('should not set any extensions if not present in options', async () => {
await startAuthentication(goodOpts1);
const argsExtensions = mockNavigatorGet.mock.calls[0][0].publicKey.extensions;
expect(argsExtensions).toEqual(undefined);
-
- done();
});
-test('should include extension results', async done => {
+test('should include extension results', async () => {
const extResults: AuthenticationExtensionsClientOutputs = {
appid: true,
credProps: {
@@ -206,14 +192,10 @@ test('should include extension results', async done => {
const response = await startAuthentication(goodOpts1);
expect(response.clientExtensionResults).toEqual(extResults);
-
- done();
});
-test('should include extension results when no extensions specified', async done => {
+test('should include extension results when no extensions specified', async () => {
const response = await startAuthentication(goodOpts1);
expect(response.clientExtensionResults).toEqual({});
-
- done();
});
diff --git a/packages/browser/src/methods/startRegistration.test.ts b/packages/browser/src/methods/startRegistration.test.ts
index e11718e..76a01fb 100644
--- a/packages/browser/src/methods/startRegistration.test.ts
+++ b/packages/browser/src/methods/startRegistration.test.ts
@@ -63,7 +63,7 @@ afterEach(() => {
mockSupportsWebauthn.mockReset();
});
-test('should convert options before passing to navigator.credentials.create(...)', async done => {
+test('should convert options before passing to navigator.credentials.create(...)', async () => {
await startRegistration(goodOpts1);
const argsPublicKey = mockNavigatorCreate.mock.calls[0][0].publicKey;
@@ -78,11 +78,9 @@ test('should convert options before passing to navigator.credentials.create(...)
expect(credId.byteLength).toEqual(64);
expect(argsPublicKey.excludeCredentials[0].type).toEqual('public-key');
expect(argsPublicKey.excludeCredentials[0].transports).toEqual(['internal']);
-
- done();
});
-test('should return base64url-encoded response values', async done => {
+test('should return base64url-encoded response values', async () => {
mockNavigatorCreate.mockImplementation((): Promise<RegistrationCredential> => {
return new Promise(resolve => {
resolve({
@@ -103,21 +101,17 @@ test('should return base64url-encoded response values', async done => {
expect(response.rawId).toEqual('Zm9vYmFy');
expect(response.response.attestationObject).toEqual('bW9ja0F0dGU');
expect(response.response.clientDataJSON).toEqual('bW9ja0NsaWU');
-
- done();
});
-test("should throw error if WebAuthn isn't supported", async done => {
+test("should throw error if WebAuthn isn't supported", async () => {
mockSupportsWebauthn.mockReturnValue(false);
await expect(startRegistration(goodOpts1)).rejects.toThrow(
'WebAuthn is not supported in this browser',
);
-
- done();
});
-test('should throw error if attestation is cancelled for some reason', async done => {
+test('should throw error if attestation is cancelled for some reason', async () => {
mockNavigatorCreate.mockImplementation((): Promise<null> => {
return new Promise(resolve => {
resolve(null);
@@ -125,11 +119,9 @@ test('should throw error if attestation is cancelled for some reason', async don
});
await expect(startRegistration(goodOpts1)).rejects.toThrow('Registration was not completed');
-
- done();
});
-test('should send extensions to authenticator if present in options', async done => {
+test('should send extensions to authenticator if present in options', async () => {
const extensions: AuthenticationExtensionsClientInputs = {
credProps: true,
appid: 'appidHere',
@@ -145,21 +137,17 @@ test('should send extensions to authenticator if present in options', async done
const argsExtensions = mockNavigatorCreate.mock.calls[0][0].publicKey.extensions;
expect(argsExtensions).toEqual(extensions);
-
- done();
});
-test('should not set any extensions if not present in options', async done => {
+test('should not set any extensions if not present in options', async () => {
await startRegistration(goodOpts1);
const argsExtensions = mockNavigatorCreate.mock.calls[0][0].publicKey.extensions;
expect(argsExtensions).toEqual(undefined);
-
- done();
});
-test('should include extension results', async done => {
+test('should include extension results', async () => {
const extResults: AuthenticationExtensionsClientOutputs = {
appid: true,
credProps: {
@@ -178,14 +166,10 @@ test('should include extension results', async done => {
const response = await startRegistration(goodOpts1);
expect(response.clientExtensionResults).toEqual(extResults);
-
- done();
});
-test('should include extension results when no extensions specified', async done => {
+test('should include extension results when no extensions specified', async () => {
const response = await startRegistration(goodOpts1);
expect(response.clientExtensionResults).toEqual({});
-
- done();
});