lundi 3 juillet 2017

angular 2 - mock component with injectionToken dependency

Im trying to do some tests in a component that has a subcomponent in it:

this is the parent component template:

<header></header>
<snackbar></snackbar>

this snackbar component is the one that is giving me problems when I try to test the parent component: snackbar component has a dependency with injectionToken, that is used to pass to the component the appConfig (some constants) that the component requires. The appConfig is injected into the snackbar component like this:

import { APP_CONFIG, AppConfig } from '../../../../app.config';

export class SnackbarComponent implements OnInit {

  private config: MdSnackBarConfig;

  constructor(
    @Inject(APP_CONFIG) config: AppConfig
  ) {
    let snackBarConfig = new MdSnackBarConfig();
    this.config = snackBarConfig;
  }
}

the parent component tests good, but when tries to resolve the snackbar component dependency it fails since its not able to find the provider for the injectionToken dependency.

I guess that a proper way to solve this issue would be to mock the snackbar component, sandly i havent found any way that works.

Any help would be appreciated. Thanks

Aucun commentaire:

Enregistrer un commentaire