mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
[ADR-0006][AC-319] Migrate all tests to use jest mock instead of substitute (#6520)
Standardize on using jest mock instead of having two mocking frameworks which can be confusing.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { Substitute, Arg } from "@fluffy-spoon/substitute";
|
||||
import { mock, MockProxy } from "jest-mock-extended";
|
||||
|
||||
import { makeStaticByteArray } from "../../../../spec";
|
||||
import { EncryptionType } from "../../../enums";
|
||||
import { EncryptService } from "../../../platform/abstractions/encrypt.service";
|
||||
import {
|
||||
@@ -64,11 +63,16 @@ describe("EncString", () => {
|
||||
describe("decrypt", () => {
|
||||
const encString = new EncString(EncryptionType.Rsa2048_OaepSha256_B64, "data");
|
||||
|
||||
const cryptoService = Substitute.for<CryptoService>();
|
||||
cryptoService.getOrgKey(null).resolves(null);
|
||||
const cryptoService = mock<CryptoService>();
|
||||
cryptoService.hasUserKey.mockResolvedValue(true);
|
||||
cryptoService.getUserKeyWithLegacySupport.mockResolvedValue(
|
||||
new SymmetricCryptoKey(makeStaticByteArray(32)) as UserKey
|
||||
);
|
||||
|
||||
const encryptService = Substitute.for<EncryptService>();
|
||||
encryptService.decryptToUtf8(encString, Arg.any()).resolves("decrypted");
|
||||
const encryptService = mock<EncryptService>();
|
||||
encryptService.decryptToUtf8
|
||||
.calledWith(encString, expect.anything())
|
||||
.mockResolvedValue("decrypted");
|
||||
|
||||
beforeEach(() => {
|
||||
(window as any).bitwardenContainerService = new ContainerService(
|
||||
@@ -85,7 +89,7 @@ describe("EncString", () => {
|
||||
|
||||
it("result should be cached", async () => {
|
||||
const decrypted = await encString.decrypt(null);
|
||||
encryptService.received(1).decryptToUtf8(Arg.any(), Arg.any());
|
||||
expect(encryptService.decryptToUtf8).toBeCalledTimes(1);
|
||||
|
||||
expect(decrypted).toBe("decrypted");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user