0
ログインメソッドで単体テストを実装しようとしていますが、「未定義のsetRoot 'プロパティを読み取れません」エラー。ここでaurelia.setRoot( 'shell/shell')によるAureliaユニットのテストエラー。
は私のログイン方法です:
import { inject, Aurelia, NewInstance, computedFrom } from 'aurelia-framework';
import { Router } from 'aurelia-router';
import { Server, User } from 'backend/server';
import { ValidationRules, ValidationController, validateTrigger } from 'aurelia-validation';
import { ValidationRenderer } from 'resources/validation-renderer';
@Inject(ミズクラゲ、ルーター、サーバー、NewInstance.of(ValidationController)、NewInstance.of(ユーザー))
constructor(aurelia, router, server, validationController, user) {
this.router = router;
this.aurelia = aurelia;
this.validationController = validationController;
this.server = server;
this.user = user;
}
activate() {
this.validationController.validateTrigger = validateTrigger.blur;
this.validationController.addRenderer(new ValidationRenderer());
ValidationRules
.ensure(u => u.email)
.required()
.matches(/^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)
.ensure('password')
.required()
.on(this.user);
}
logUserIn()
{
let promise = new Promise((resolve, reject) =>
{
this.loggingIn = true;
this.messageColor = 'green';
this.message = 'Authenticating...';
this.loginSuccess = false;
this.validationController.validate().then(errors => {
if (!errors.valid) {
this.loggingIn = false;
return ({error: true});
}
return this.server.authenticate(this.user.email, this.user.password);
}).then(result => {
if (!result.error) {
this.messageColor = 'green';
this.message = 'Login Successful';
this.loginSuccess = true;
this.aurelia.setRoot('shell/shell');
resolve(result);
} else {
this.message = '';
resolve();
}
}).catch(err => {
if(!this.loginSuccess)
{
this.messageColor = 'red';
this.message = err.message;
}
this.loggingIn = false;
resolve(err);
});
});
return promise;
}
私のユニットテストコード: login.spec.js:
ここを取得していますエラーです。おかげさまで
はい、私はすべてのコードを正しくコピーしていませんでした。 @inject(Aurelia、Router、Server、NewInstance.of(ValidationController)、NewInstance.of(User)) – raj
私は自分の質問を更新しました – raj