I am currently in the process of creating a test scenario for a dispatch event. Below is the code snippet I am working on:
@Injectable()
export class AuthEffects {
signIn$ = createEffect(() =>
this.actions$.pipe(
ofType(AuthActions.signIn),
switchMap((action) =>
from(this.loginService.signIn(action.email, action.password, action.redirectTo)).pipe(
map(() => AuthActions.signInSuccess()),
catchError((err: Error) =>
of(
AuthActions.signInError({
message: err.message,
})
)
)
)
)
)
);
constructor(
private actions$: Actions,
private loginService: LoginService
) {}
}
Below is the outline for the test:
describe('AuthEffects', () => {
let effects: AuthEffects;
let actions$: Observable<Action>;
let mockLoginService: LoginService;
let mockSupabaseService: SupabaseService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [provideMockActions(() => actions$), AuthEffects],
});
effects = TestBed.inject(AuthEffects);
mockLoginService = TestBed.inject(LoginService);
mockSupabaseService = TestBed.inject(SupabaseService);
});
describe('signIn$', () => {
// Test scenarios go here
});
});
I am encountering difficulties with simulating the output needed to achieve full coverage on the catchError
method. Whenever I execute the test, the error below crops up:
console.error
Unhandled Promise rejection: { name: 'test', message: 'test' } ; Zone: ProxyZone ; Task: null ; Value: { name: 'test', message: 'test' } undefined
How can I resolve this issue?