angular-docs-cn/packages/zone.js/lib
JiaLiPassion c2b4d92708 feat(zone.js): patch jasmine.createSpyObj to make properties enumerable to be true (#34624)
Close #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 #34624
2020-06-29 12:22:08 -07:00
..
browser build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
closure build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
common fix(zone.js): remove unused Promise overwritten setter logic (#36851) 2020-06-11 18:56:19 -07:00
extra fix(zone.js): remove unused Promise overwritten setter logic (#36851) 2020-06-11 18:56:19 -07:00
jasmine feat(zone.js): patch jasmine.createSpyObj to make properties enumerable to be true (#34624) 2020-06-29 12:22:08 -07:00
jest build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
mix build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
mocha build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
node build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
rxjs build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
testing build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
zone-spec feat(zone.js): upgrade zone.js to angular package format(APF) (#36540) 2020-06-11 11:08:48 -07:00
BUILD.bazel refactor: update to tslib 2.0 and move to direct dependencies (#37198) 2020-05-19 14:57:09 -07:00
zone.api.extensions.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
zone.configurations.api.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
zone.ts fix(zone.js): remove unused Promise overwritten setter logic (#36851) 2020-06-11 18:56:19 -07:00