What other interesting things can we test? We can test whether the first exercise has started. We add this test to workout.spec.ts after the one we just added:
it('should start the first exercise', () => { spyOn(runner, 'startExercise').and.callThrough(); runner.ngOnInit(); runner.ngDoCheck(); expect(runner.currentExerciseIndex).toEqual(0); expect(runner.startExercise).toHaveBeenCalledWith( runner.workoutPlan.exercises[runner.currentExerciseIndex]); expect(runner.currentExercise).toEqual( runner.workoutPlan.exercises[0]); });
The second expect function in this test is interesting. It uses a Jasmine feature: spies. Spies can be used to verify method invocations and dependencies.