jeudi 18 février 2021

Angular testing: mock the value of a constant

I have a simple app:

  • AppComponent gets a list of activities to display from a service
  • ActivitiesService gets the list from an imported constant
  • in my test file activities.service.spec.ts I would like to mock that constant

For convenience I've set up a StackBlitz (including the test) in 'given/when/then' form (link) and another one with the classic 'beforeEach/it()' form (link). They should be doing the same thing but some people like one style better than the other... I'd be happy if any of the two was running.

In the test I'm adding { provide: ACTIVITIES, useValue: fakeActivities }, since I believe the solution has to lay there somewhere... but how do I apply it? Apparently I cannot inject it...

Aucun commentaire:

Enregistrer un commentaire