Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: investigate the issue #7495

Open
satanTime opened this issue Nov 20, 2023 · 2 comments
Open

Bug: investigate the issue #7495

satanTime opened this issue Nov 20, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@satanTime
Copy link
Member

satanTime commented Nov 20, 2023

https://stackoverflow.com/questions/77329862/ngmocks-error-ng0204-cant-resolve-all-parameters-for-pinresolver

ngMocks .... Error: NG0204: Can't resolve all parameters for PinResolver: (?, ?)

i am getting error within test... i use ngMocks...
i used test from this documentation as template:
https://ng-mocks.sudo.eu/guides/routing-resolver
only difference that i can see is that i am using standalone components ... so there is no target module as in example within documentation
pls? how should i mock parameters of this resolver

resolver:

export const PinResolver: ResolveFn<string> = (_, routerState: RouterStateSnapshot): Observable<string> => {
  const router = inject(Router);
  const toastService = inject(ToastService);
  const cardsService = inject(CardsService);
  const crypto = inject(CryptoService);
  const encOneTimeKey = crypto.encOneTimeKey;

  return crypto.setRsaKey(environment.danubepayRsaUrl.epin, 'pin').pipe(
    catchError(() => handleError(router, toastService)),
    switchMap(() =>
      cardsService
        .getPin(getCardId(routerState), crypto.pkFingerPrintKey('pin'), crypto.encryptWithRSA(encOneTimeKey, 'pin'))
        .pipe(
          map((res) => crypto.decryptTDES(res, encOneTimeKey)),
          concatMap((pin) => (pin === '' ? throwError(() => new Error('Cant decode the pinBlock')) : of(pin))),
          catchError(() => handleError(router, toastService)),
        ),
    ),
  );
};

test:

describe('PinResolver:fn', () =\> {
beforeEach(() =\> {
return MockBuilder(\[ActivatedRoute, RouterModule, RouterTestingModule.withRoutes(\[\]), NG_MOCKS_ROOT_PROVIDERS\])
.exclude(NG_MOCKS_GUARDS)
.exclude(NG_MOCKS_RESOLVERS)
.keep(PinResolver);
});

it('provides data to on the route', fakeAsync(() =\> {
const fixture = MockRender(RouterOutlet, {});
const router = ngMocks.get(Router);
const routerStateSnapshot = ngMocks.get(RouterStateSnapshot);
const location = ngMocks.get(Location);
const cardsService = ngMocks.get(CardsService);
const crypto = ngMocks.get(CryptoService);
const type = 'pin';

    cardsService.getPin = () => from(['1111']);
    
    location.pathname = '/pin';
    
    if (fixture.ngZone) {
      fixture.ngZone.run(() => router.initialNavigation());
      tick();
    }
    
    expect(location.pathname).toEqual('/cards/103867599/pin');
    
    const el = ngMocks.find(PinComponent);
    const route = ngMocks.findInstance(el, ActivatedRoute);
    
    expect(route.snapshot.data).toEqual({
      pin: {
        pinBlock: '1234',
      },
    });

}));
});

i try to follow ngMocks documentation but without success

@satanTime satanTime added the bug Something isn't working label Nov 20, 2023
@satanTime satanTime assigned satanTime and unassigned satanTime Nov 20, 2023
@Morad-m11
Copy link
Contributor

Morad-m11 commented Nov 25, 2023

@satanTime The question seems to have been removed

@satanTime
Copy link
Member Author

Hi @Morad-m11, thanks not noting! I've copy-pasted the original description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants