1

I have a component where in my .spec.ts file, I need to spy on a property instead of a method with Jasmine. I heard that Jasmine doesn't provide this option. I see some options provided in this link

Is this the only way or do we have any other alternative.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
user7000
  • 99
  • 2
  • 9
  • If you initialize the component in your spec then you should be able to access any properties of the component _directly_. `component.varName` just like any other object. – Z. Bagley Nov 29 '17 at 01:07
  • 1
    @user7000 What exactly do you want to spy on? Unless you're spying on property reads (which is quite pointless), there's no need for extra actions. The reason why Jasmine spies are separate entities is because they have special traits; their calls can be spied, and their returned values can be mocked. Properties don't need anything like that. – Estus Flask Nov 29 '17 at 01:25
  • @Bagley, for some reason when I say component.varname, it says varname not available.I think I am initialising the service which has the varname – user7000 Nov 29 '17 at 02:23
  • @estus, ddin't clearly understand what you said – user7000 Nov 29 '17 at 02:24
  • There are no spies for properties because they aren't needed. *it says varname not available* - then provide http://stackoverflow.com/help/mcve that can replicate your problem and contains clear problem statement. The question is off-topic otherwise. – Estus Flask Nov 29 '17 at 03:05
  • Jasmine now has spyOnProperty, but it doesn't appear to work on components. In my case, I have bound a boolean property to the condition of a progress spinner, and want to verify that this property is set true, and subsequently false. Is there a better way that I can test this? – plantbeard Apr 30 '19 at 02:10

0 Answers0