我想测试 .get 的 get 和 set 方法my user.store.ts。我有一个get()用于获取users和addUsers()用于将用户添加到BehaviourSubject. 我怎样才能做到这一点?
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { User } from 'ngx-login-client';
@Injectable({
providedIn: 'root'
})
export class UserStore {
private _users: BehaviorSubject<User[]> = new BehaviorSubject([]);
get users() {
return this._users.asObservable();
}
addUsers(users: User[]) {
this._users.next(users);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望输出是在addUsers()调用时添加的值,并且get在调用时可以添加用户。我get users()是 Angular 测试的新手。
得到类似的错误:
Expected Observable({ _isScalar: false, source: BehaviorSubject({ …
我正在尝试连接到托管在 上的本地 Kubernetes 集群minikube,这是相同的代码,现在当我这样做时go run minikube.go,它给了我一个错误说:
../../../pkg/mod/k8s.io/client-go@v11.0.0+incompatible/kubernetes/scheme/register.go:26:2: module k8s.io/api@latest found (v0.19.0), but does not contain package k8s.io/api/auditregistration/v1alpha1`.
Run Code Online (Sandbox Code Playgroud)
现在,我尝试使用手动安装该软件包,go get然后我发现该软件包不存在。我怎样才能让它工作并解决这个问题?我的go.mod 文件,以防有人想看。
如何测试canActivateangular 的函数,该函数返回一个函数,该函数又返回一个boolean值?。
我尝试创建ActivatedrouterSnapshotand 的对象routerStateSnapshot并将其传递给canActivate函数,但这没有帮助。
export class AuthGuard implements CanActivate {
constructor(
private authService: AuthenticationService,
private loginService: LoginService,
private router: Router
) {}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean>
| boolean {
return this.checkLogin(state.url);
}
checkLogin(url: string): boolean {
if (this.authService.isLoggedIn()) { return true; }
// Store the attempted URL for redirecting
this.loginService.redirectUrl = url;
// Navigate to the login page with extras
this.router.navigate(['/login']);
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
自从 …
我有一个userService.spec.ts要测试的文件。代码就是这样。它调用了一个get函数,该函数调用了ADMIN_API_URL。我尝试测试给定的文件,但标题中提到了错误。我的user.service.spec.ts文件。
describe('Service: User service', () => {
let httpMock: HttpTestingController;
let userService: UserService;
let url: string;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
{ provide: AUTH_API_URL, useValue: 'https://auth.example.com/api/'
},
{ provide: SSO_API_URL, useValue: 'https://sso.example.com/auth/api/' },
{ provide: WIT_API_PROXY, useValue: 'https://wit.example.com/api/'},
{ provide: ADMIN_API_URL, useValue: 'https://admin.example.com/api/'},
{ provide: REALM, useValue: 'realm' },
Broadcaster,
Logger,
AuthenticationService,
HttpHandler,
UserService
]
});
httpMock = TestBed.get(HttpTestingController);
url = TestBed.get(ADMIN_API_URL);
userService = TestBed.get(UserService);
});
it('Get user by user name …Run Code Online (Sandbox Code Playgroud) 当我尝试这样做时ng build,我收到一条错误消息
ERROR in node_modules/@angular/common/http/http.d.ts:81:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.
This likely means that the library (@angular/common/http) which declares HttpClient has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible …Run Code Online (Sandbox Code Playgroud) angular ×3
angular6 ×3
angular7 ×3
unit-testing ×2
angular10 ×1
go ×1
go-modules ×1
go-packages ×1
httpclient ×1
kubernetes ×1
typescript ×1