feat(zone.js): patch jasmine.createSpyObj to make properties enumerable to be true#34624
feat(zone.js): patch jasmine.createSpyObj to make properties enumerable to be true#34624JiaLiPassion wants to merge 1 commit intoangular:masterfrom
Conversation
cafc24b to
05c8953
Compare
05c8953 to
74ee80b
Compare
74ee80b to
bb5bbac
Compare
bb5bbac to
30063e3
Compare
|
FYI, I re-labeled this PR to be "master-only", since it's marked as a feature (so it should not go to the patch branch in this case). Thank you. |
|
@AndrewKushnir, got it, thank you. |
|
@JiaLiPassion FYI the presubmit looks good. Since this PR is a feature, it may need to wait until master becomes available for v10.1 features. Thank you. |
|
@AndrewKushnir, got it, thank you. |
|
FYI, global presubmit went well, but the merge script indicated that this PR needs a rebase. @JiaLiPassion could you please rebase it when you get a chance? Thank you. |
…le to be true Close angular#33657 in jasmine 3.5, there is a new feature, user can pass a properties object to `jasmine.createSpyObj` ``` const spy = jasmine.createSpyObj('spy', ['method1'], {prop1: 'foo'}); expect(spy.prop1).toEqual('foo'); ``` This case will not work for Angular TestBed, for example, ``` describe('AppComponent', () => { beforeEach(() => { //Note the third parameter // @ts-ignore const someServiceSpy = jasmine.createSpyObj('SomeService', ['someFunction'], ['aProperty']); TestBed.configureTestingModule({ declarations: [ AppComponent ], providers: [ {provide: SomeService, useValue: someServiceSpy}, ] }).compileComponents(); }); it('should create the app', () => { //spyObj will have someFunction, but will not have aProperty let spyObj = TestBed.get(SomeService); }); ``` Because `jasmine.createSpyObj` will create the `aProperty` with `enumerable=false`, and `TestBed.configureTestingModule` will try to copy all the properties from spyObj to the injected service instance. And because `enumerable` is false, so the property (here is aProperty) will not be copied. This PR will monkey patch the `jasmine.createSpyObj` and make sure the new property's `enumerable=true`.
30063e3 to
53a1c71
Compare
|
Hi, @AndrewKushnir, thanks and I just rebased the PR, it seems the |
|
Thanks for rebasing this PR @JiaLiPassion 👍 The |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
…le to be true (angular#34624) Close angular#33657 in jasmine 3.5, there is a new feature, user can pass a properties object to `jasmine.createSpyObj` ``` const spy = jasmine.createSpyObj('spy', ['method1'], {prop1: 'foo'}); expect(spy.prop1).toEqual('foo'); ``` This case will not work for Angular TestBed, for example, ``` describe('AppComponent', () => { beforeEach(() => { //Note the third parameter // @ts-ignore const someServiceSpy = jasmine.createSpyObj('SomeService', ['someFunction'], ['aProperty']); TestBed.configureTestingModule({ declarations: [ AppComponent ], providers: [ {provide: SomeService, useValue: someServiceSpy}, ] }).compileComponents(); }); it('should create the app', () => { //spyObj will have someFunction, but will not have aProperty let spyObj = TestBed.get(SomeService); }); ``` Because `jasmine.createSpyObj` will create the `aProperty` with `enumerable=false`, and `TestBed.configureTestingModule` will try to copy all the properties from spyObj to the injected service instance. And because `enumerable` is false, so the property (here is aProperty) will not be copied. This PR will monkey patch the `jasmine.createSpyObj` and make sure the new property's `enumerable=true`. PR Close angular#34624
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #33657
Close #33657
in jasmine 3.5, there is a new feature, user can pass a properties object to
jasmine.createSpyObjThis case will not work for Angular TestBed, for example,
Because
jasmine.createSpyObjwill create theaPropertywithenumerable=false,and
TestBed.configureTestingModulewill try to copy all the properties from spyObj tothe injected service instance. And because
enumerableis false, so the property (here is aProperty)will not be copied.
This PR will monkey patch the
jasmine.createSpyObjand make sure the new property'senumerable=true.