Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): use TestBed.get if .inject falsy - back compatibility (#283) #284

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions projects/spectator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"replace-in-file": "^4.1.3"
},
"peerDependencies": {
"@angular/common": "^9.0.1",
"@angular/core": "^9.0.1",
"@angular/router": "^9.0.1",
"@angular/common": "^8.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't include v9. You need to use a range.

"@angular/core": "^8.0.0",
"@angular/router": "^8.0.0",
"typescript": ">= 3.7.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"typescript": ">= 2.8.0"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me check with this version of typescript,
I haven't checked it and not sure there are no new typescript features that are used in code which will not work with 2.8.0.

I will update you

Copy link
Contributor Author

@Coffee-Tea Coffee-Tea Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NetanelBasal I would put "typescript": ">= 3.5.3" or smth like that b/c there are a bunch of errors when using 2.8.0. Actually, 3.5.3 was used as dependency in the root package.json:
e13c955#diff-b9cfc7f2cdf78a7f4b91a753d10865a2L77

Here is a part of errors I'm getting with 2.8.0:
image

Please confirm

Copy link
Member

@NetanelBasal NetanelBasal Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the lastest version before we released v5:

"typescript": ">= 2.8.0"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NetanelBasal yes you're right, but what is goal of peerDependencies? Maybe I'm wrong but should not we specify versions which gonna work with other specified peerDependencies versions?
I assume that it was wrong with >= 2.8.0 but if you're ok I will get back to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used 8.2.0, my bad, but even typescript 3.0.0 was not working with 8.2.0.
Angular 8.2.0 was properly working with typescript 3.5.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check 2.8.0 with 8.0.0

Copy link
Contributor Author

@Coffee-Tea Coffee-Tea Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work for me trying 2.8.0 with 8.0.0,
also 8.0.0 angular is using 3.4.2 version https:/angular/angular/blob/38a7e2a775d2c3495a8574dde7d1a7106dd0ae04/package.json#L108

so I'm really unsure in 2.8.0 but pushed it. It doesn't break anything, just seems to be smth like disinformation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TS version depends on your Angular version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that what I mean, and I'm not sure that TS 2.8.0 is compatible with Angular 8.0.0 :)

},
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions projects/spectator/src/lib/base/base-spectator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestBed } from '@angular/core/testing';
import { TestBed, TestBedStatic } from '@angular/core/testing';

import { SpyObject } from '../mock';
import { Token } from '../token';
Expand All @@ -17,6 +17,6 @@ export abstract class BaseSpectator {
}

public inject<T>(token: Token<T>): SpyObject<T> {
return TestBed.inject(token) as SpyObject<T>;
return (<any>TestBed).inject ? ((<any>TestBed).inject(token) as SpyObject<T>) : TestBed.get(token);
}
}
6 changes: 5 additions & 1 deletion projects/spectator/src/lib/spectator-http/create-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export function createHttpFactory<S>(typeOrOptions: Type<S> | SpectatorHttpOptio
});

afterEach(() => {
TestBed.inject(HttpTestingController).verify();
if ((<any>TestBed).inject) {
(<any>TestBed).inject(HttpTestingController).verify();
} else {
TestBed.get(HttpTestingController).verify();
}
});

return (overrides?: CreateHttpOverrides<S>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Provider, Type } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { TestBed, TestBedStatic } from '@angular/core/testing';

import { BaseSpectatorOverrides } from '../base/options';
import { isType, doesServiceImplementsOnDestroy } from '../types';
Expand Down Expand Up @@ -33,7 +33,9 @@ export function createServiceFactory<S>(typeOrOptions: Type<S> | SpectatorServic
});

afterEach(() => {
const testedService = TestBed.inject<S>(service);
const testedService = (<any>TestBed).inject
? (<{ inject<T>(token: Type<T>, notFoundValue?: T): T } & TestBedStatic>TestBed).inject<S>(service)
: TestBed.get(service);

if (doesServiceImplementsOnDestroy(testedService)) {
// tslint:disable-next-line:no-life-cycle-call
Expand Down