First of, spyOnProperty is giving me Property user does not have access type get with this line: spyOnProperty(userService, 'user', 'get').and.returnValue(Observable.of(adminUser));
I have a UserService with a user property as such:
export class UserService {
user: BehaviorSubject<User> = new BehaviorSubject(new User());
}
The component that I'm testing needs to change behavior depending on the result of userService.user.subscribe. Hence, I need to be able to spy on user.
One idea that I had was to write a method getter, eg getUser() on class UserService, and don't access user via a property.
But that seems to be a bit extreme.
Any ideas?
SpyOn is a Jasmine feature that allows dynamically intercepting the calls to a function and change its result.
You can use spyOnProperty to return user object's mock.
spyOnProperty(userService.user, 'value', 'get').and.returnValue({ 'username': 'username'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With