Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/tests/expoLazyLoading.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ describe("ExpoSecureStore lazy loading", () => {
});

it("should dynamically import ExpoSecureStore when accessed", async () => {
// Setup a mock class that will be returned by our dynamic import
const MockStore = vi.fn().mockImplementation(() => ({
getSessionItem: vi.fn().mockResolvedValue("mock-value"),
setSessionItem: vi.fn().mockResolvedValue(undefined),
removeSessionItem: vi.fn().mockResolvedValue(undefined),
destroySession: vi.fn().mockResolvedValue(undefined),
}));
// Setup a mock class (function constructor) that will be returned by our dynamic import
function MockStore(this: mainExports.SessionManager<StorageKeys>) {
this.getSessionItem = vi.fn().mockResolvedValue("mock-value");
this.setSessionItem = vi.fn().mockResolvedValue(undefined);
this.removeSessionItem = vi.fn().mockResolvedValue(undefined);
this.destroySession = vi.fn().mockResolvedValue(undefined);
}

// Create a spy for the dynamic import
const importSpy = vi.fn().mockResolvedValue({
ExpoSecureStore: MockStore,
ExpoSecureStore: MockStore as unknown as new () => unknown,
});

// Replace the getter with our spy
Expand All @@ -102,7 +102,8 @@ describe("ExpoSecureStore lazy loading", () => {
expect(moduleExport).toEqual({ ExpoSecureStore: MockStore });

// Create an instance to verify it works
const instance = new MockStore();
const instance =
new (MockStore as unknown as new () => mainExports.SessionManager<StorageKeys>)();
expect(instance).toBeDefined();

// Test a method to make sure it works
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/chrome": "^0.1.0",
"@types/node": "^22.5.1",
"@vitejs/plugin-react": "^5.0.0",
"@vitest/coverage-v8": "^3.0.0",
"@vitest/coverage-v8": "^4.0.3",
"eslint": "^9.9.1",
"globals": "^16.0.0",
"jsdom": "^27.0.0",
Expand All @@ -50,7 +50,7 @@
"typescript-eslint": "^8.3.0",
"vite": "^7.0.0",
"vite-plugin-dts": "^4.0.3",
"vitest": "^3.0.0",
"vitest": "^4.0.3",
"vitest-fetch-mock": "^0.4.1"
},
"peerDependencies": {
Expand Down
Loading