You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a really, really weird one. I'm not even sure this is actually karma-typescript's fault, but it doesn't happen when using karma-webpack instead. Repro here.
The short version is, I'm passing a Jasmine SpyObj to providers: [{useValue: ...}] in testBed.configureTestingModule. At some point, this object is getting copied in such a way that callFake is referencing the closure-scoped original object, but the spec is manipulating the copy, resulting in tests that set a value on one object then read it from a different one.
I've got a workaround in the repro (using this.someValue instead of ret.someValue) but I already wrote a ton of mocks this way and it's going to be very time consuming to switch everything over to the other syntax. If you have any ideas, I'm all ears. (If this is my fault, for the way I'm using it, or Karma's fault, or Jasmine's fault, I'm happy to bug them instead.)
The text was updated successfully, but these errors were encountered:
This is worse than I thought. I had the workaround of using this to refer to the property, which works for spy-object methods, since callFake is preserved. But I don't have such a workaround for spy-object properties.
The end of this Jasmine tutorial shows a way to use Object.getOwnPropertyDescriptor to retrieve the jasmine.Spy that wraps properties created by jasmine.createSpyObj. This lets you attach a spy strategy (like callFake) to the spies after creation -- as far as I know, this is the only way to implement a spy object with getters or setters.
Whatever is happening here, the getters and setters are being removed. I've updated the repro with an example, but basically, when constructing the mock I can attach getters or setters to properties using the descriptor, but then when I go to configure the mock during a spec, the descriptor is gone, and what was once a getter is now a simple property again.
I don't know how to work around this, other than ditching Jasmine spies altogether and writing my own configurable mock-objects. I'd really appreciate any insight you have.
This is a really, really weird one. I'm not even sure this is actually karma-typescript's fault, but it doesn't happen when using karma-webpack instead. Repro here.
The short version is, I'm passing a Jasmine SpyObj to
providers: [{useValue: ...}]
in testBed.configureTestingModule. At some point, this object is getting copied in such a way thatcallFake
is referencing the closure-scoped original object, but the spec is manipulating the copy, resulting in tests that set a value on one object then read it from a different one.I've got a workaround in the repro (using
this.someValue
instead ofret.someValue
) but I already wrote a ton of mocks this way and it's going to be very time consuming to switch everything over to the other syntax. If you have any ideas, I'm all ears. (If this is my fault, for the way I'm using it, or Karma's fault, or Jasmine's fault, I'm happy to bug them instead.)The text was updated successfully, but these errors were encountered: