NullInjectorError:Angular中没有路由器测试用例的提供者

时间:2020-02-18 16:54:47

标签: angular karma-jasmine router

我正在使用以下component.ts,但出现错误

StaticInjectorError(DynamicTestModule)[UploadDocumentsLoginContainerComponent->路由器]: StaticInjectorError(平台:核心)[UploadDocumentsLoginContainerComponent->路由器]: NullInjectorError:没有路由器的提供程序!

kubectl get clusterissuer letsencrypt -o yaml

测试用例:

var canvas = document.querySelector("#demo_canvas");
var ctx = canvas.getContext("2d");

var pg = canvas.getContext("2d");

var xPos = 75;
var yPos = 75;

function draw() {
 ctx.rect(50, 50, 150, 100);
 ctx.stroke();

 ctx.rect(250, 50, 150, 100);
 ctx.stroke();

 ctx.rect(450, 50, 150, 100);
 ctx.stroke();

 ctx.rect(250, 200, 150, 100);
 ctx.stroke();

 pg.rect(xPos, yPos, 50, 50);
 pg.stroke();
};

draw();
console.log("x = " + xPos + ", y = " + yPos);


function move(e) {

 //ARROW KEY RIGHT
 if (e.keyCode == 39) {
  if (xPos == 75 && yPos == 75) {
   xPos += 225;
  }
  else if (xPos == 300 && yPos == 75) {
   xPos += 225;
  };
 };

 //ARROW KEY LEFT
 if (e.keyCode == 37) {
  if (xPos == 75 && yPos == 75) {
   xPos -= 0;
  }
  else if (xPos == 300 && yPos == 75) {
   xPos -= 225;
  }
  else if (xPos == 525 && yPos == 75) {
   xPos -= 225;
  };
 };

 //ARROW KEY UP
 if (e.keyCode == 38) {
  if (yPos == 75) {
   yPos -= 0;
  }
  else if (yPos == 225) {
   yPos -= 150;
  }
 };

 //ARROW KEY DOWN
 if (e.keyCode == 40) {
  if (yPos == 75 && xPos == 300) {
   yPos += 150;
  }
 };

 canvas.width = canvas.width;
 draw();
 console.log("x = " + xPos + ", y = " + yPos);
};

document.onkeydown = move;

为解决以上错误,我在路由器下方添加了

export class UploadDocumentsLoginContainerComponent implements OnInit {
constructor(
    private fb: FormBuilder,
    private loanStore: Store<LoanState>,
    private router: Router,
    **private activateRoute: ActivatedRoute,**
    private urlProviderService: UrlProviderService
  ) {
    this.activateRoute.queryParams.subscribe(params => {
      this.isMyAccountRequest = params[IS_MY_ACCOUNT];
    });
  }

  ngOnInit() {}

  //on button click
   routeSignin() {
    if (this.isMyAccountRequest) {
      this.router.navigate(['/home']);
    }
  }
}

后来又出现一个错误

UploadDocumentsContainerComponent √应该创造 HeadlessChrome 75.0.3770(Windows 10.0.0)错误 { “ message”:“ afterAll中引发错误\ n错误:无法从同步测试中调用Promise。然后

请建议我如何解决此测试用例错误?

0 个答案:

没有答案
相关问题