茉莉花:处理Promise.resolve()。然后在ngOnInit中

时间:2018-10-26 13:45:52

标签: javascript angular testing promise jasmine

加载我的角度组件时,它会显示一个模态(ng-bootstrap)。

在我的测试中,我尝试访问此模式,但由于在测试运行后似乎已加载,因此无法访问它。

component.ts

Removing .m2/antlr/
Removing .m2/aopalliance/
Removing .m2/asm/
Removing .m2/avalon-framework/
Removing .m2/backport-util-concurrent/
Removing .m2/ch/
Removing .m2/classworlds/
Removing .m2/com/
Removing .m2/commons-beanutils/
Removing .m2/commons-chain/
Removing .m2/commons-cli/
Removing .m2/commons-codec/
Removing .m2/commons-collections/
Removing .m2/commons-digester/
Removing .m2/commons-io/
Removing .m2/commons-lang/
Removing .m2/commons-logging/
Removing .m2/commons-validator/
Removing .m2/dom4j/
Removing .m2/io/
Removing .m2/javax/
Removing .m2/junit/
Removing .m2/log4j/
Removing .m2/logkit/
Removing .m2/net/
Removing .m2/org/
Removing .m2/oro/
Removing .m2/sslext/
Removing .m2/xml-apis/
Removing .m2/xmlunit/
Removing jfrog
Removing target/

component.spec.ts

stages:
- build
- deploy-artifactory

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=${CI_PROJECT_DIR}/.m2"
  MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"

cache:
  key: "$CI_JOB_NAME"
  paths:
  - .m2/

build:
  image: maven:latest
  stage: build
  tags:
  - build
  script:
  - adduser --disabled-password --gecos '' mynonrootuser
  - chmod --recursive 777 .
  - git version
  - su --command='mvn versions:set -DgenerateBackupPoms=false -DnewVersion="$CI_COMMIT_REF_SLUG-SNAPSHOT"' mynonrootuser
  - su --command='mvn $MAVEN_CLI_OPTS clean install -B -f ./pom.xml' mynonrootuser
  artifacts:
    expire_in: 5 mins
    paths:
    - target/*.jar

  only:
  - develop

deploy-artifactory-snapshot:
  retry: 2
  image: maven:latest
  stage: deploy-artifactory
  tags:
  - release
  before_script:
  -  curl -fL https://getcli.jfrog.io | sh
  - ./jfrog rt config --url=${ARTIFACTORY_URL} --user=${ARTIFACTORY_USER} --password=${ARTIFACTORY_PASSWORD}
  - ./jfrog rt c show
  - export M2_HOME=/usr/share/maven
  - sed -i 's,MAVEN_REPO_SNAPSHOT_DEPLOYER,'"$MAVEN_REPO_SNAPSHOT_DEPLOYER"',g' configuration.yml
  - sed -i 's,MAVEN_REPO_RELEASES_DEPLOYER,'"$MAVEN_REPO_RELEASES_DEPLOYER"',g' configuration.yml
  - sed -i 's,MAVEN_REPO_SNAPSHOT_RESOLVER,'"$MAVEN_REPO_SNAPSHOT_RESOLVER"',g' configuration.yml
  - sed -i 's,MAVEN_REPO_RELEASES_RESOLVER,'"$MAVEN_REPO_RELEASES_RESOLVER"',g' configuration.yml
  script:
  - ./jfrog rt mvn "versions:set -DgenerateBackupPoms=false -Dartifactory.publish.artifacts=false -DnewVersion="$CI_COMMIT_REF_SLUG-SNAPSHOT"" configuration.yml --build-name=scdfrestrunner --build-number=$CI_JOB_ID
  - ./jfrog rt mvn "clean install" configuration.yml --build-name=scdfrestrunner --build-number=$CI_JOB_ID
  - ./jfrog rt bce scdfrestrunner $CI_JOB_ID
  - ./jfrog rt bp scdfrestrunner $CI_JOB_ID

  only:
  - develop

运行测试时,我收到以下错误消息:

ngOnInit() {
    Promise.resolve().then(() => { // promise is needed because of angular bug: https://github.com/angular/angular/issues/15634
      this.ciamModal = this.modalService.open(this.ciamcheck, {ariaLabelledBy: "modal-basic-title", keyboard: false});
      this.ciamModal.result.then((result) => {
        // will be closed from code
      }, (reason) => {
        this.router.navigate(["/somewhere"]);
      });
    });
  }

我已经尝试过用fakeAsync和tick()进行几种不同的方法,并且不使用具有不同变化的异步方法-效果相同或类似,如上所示。

有人对我有一些正确的建议吗?

更新:我创建了一个Stackblitz来重新创建问题

0 个答案:

没有答案