Skip to content

Commit 5161ad5

Browse files
fix: correct typecheck errors in auth.local.service.test.ts
1 parent 8792cb5 commit 5161ad5

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎src/modules/authentication/infrastructure/__tests__/auth.local.service.test.ts‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
* inicialicen en el momento de la declaración.
1313
*/
1414

15-
import type {
16-
AuthStateChangeCallback,
17-
AuthUser,
18-
} from '../../domain/auth.model';
15+
import type { AuthUser } from '../../domain/auth.model';
1916

2017
// Store compartido por storage y secureStorage. Inicializado inline
2118
// (no lazy) para que esté disponible cuando jest.mock() ejecute su
@@ -222,6 +219,10 @@ describe('AuthLocalService', () => {
222219

223220
const result = await authLocalService.getCurrentUser();
224221
expect(result).not.toBeNull();
222+
expect(result).not.toBeInstanceOf(Error);
223+
if (result instanceof Error) {
224+
return;
225+
}
225226
expect(result!.email).toBe('frank@example.com');
226227
expect(result!.id).toBe(signup.user.id);
227228
});
@@ -247,7 +248,7 @@ describe('AuthLocalService', () => {
247248
password: 'Secret123',
248249
});
249250

250-
const callback = jest.fn<AuthStateChangeCallback>();
251+
const callback = jest.fn<void, [AuthUser | null]>();
251252
const unsubscribe = authLocalService.onAuthStateChanged(callback);
252253

253254
expect(callback).toHaveBeenCalledTimes(1);
@@ -258,15 +259,15 @@ describe('AuthLocalService', () => {
258259
});
259260

260261
it('notifica null si no hay sesión activa', () => {
261-
const callback = jest.fn<AuthStateChangeCallback>();
262+
const callback = jest.fn<void, [AuthUser | null]>();
262263
authLocalService.onAuthStateChanged(callback);
263264

264265
expect(callback).toHaveBeenCalledWith(null);
265266
});
266267

267268
it('notifica a todos los listeners en signup / signout', async () => {
268-
const cb1 = jest.fn<AuthStateChangeCallback>();
269-
const cb2 = jest.fn<AuthStateChangeCallback>();
269+
const cb1 = jest.fn<void, [AuthUser | null]>();
270+
const cb2 = jest.fn<void, [AuthUser | null]>();
270271
const off1 = authLocalService.onAuthStateChanged(cb1);
271272
const off2 = authLocalService.onAuthStateChanged(cb2);
272273

@@ -301,7 +302,7 @@ describe('AuthLocalService', () => {
301302
});
302303

303304
it('la función devuelta cancela la suscripción', async () => {
304-
const callback = jest.fn<AuthStateChangeCallback>();
305+
const callback = jest.fn<void, [AuthUser | null]>();
305306
const unsubscribe = authLocalService.onAuthStateChanged(callback);
306307

307308
callback.mockClear();
@@ -331,6 +332,10 @@ describe('AuthLocalService', () => {
331332
expect(result).toBeUndefined();
332333

333334
const current = await authLocalService.getCurrentUser();
335+
expect(current).not.toBeInstanceOf(Error);
336+
if (current instanceof Error) {
337+
return;
338+
}
334339
expect(current!.emailVerified).toBe(true);
335340
});
336341

@@ -379,6 +384,10 @@ describe('AuthLocalService', () => {
379384
expect(result.photoURL).toBe('https://example.com/avatar.png');
380385

381386
const current = await authLocalService.getCurrentUser();
387+
expect(current).not.toBeInstanceOf(Error);
388+
if (current instanceof Error) {
389+
return;
390+
}
382391
expect(current!.displayName).toBe('Liam Updated');
383392
expect(current!.photoURL).toBe('https://example.com/avatar.png');
384393
});

0 commit comments

Comments
 (0)