【问题标题】:How to unit test Ionic 3 apps如何对 Ionic 3 应用程序进行单元测试
【发布时间】:2019-11-14 16:55:09
【问题描述】:

我想对我的 ionic 3 应用程序进行单元测试。

我无法运行以下命令 npm test、ng test 等。我也安装了 angular cli,但无法运行测试命令。

下面是我的 package.json

    {
    "name": "XYZ",
    "version": "0.0.1",
    "author": "Ionic Framework",
    "homepage": "http://ionicframework.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve",
        "test": "ng test"
    },
    "dependencies": {
        "@angular/animations": "^5.2.11",
        "@angular/common": "5.2.11",
        "@angular/compiler": "5.2.11",
        "@angular/compiler-cli": "5.2.11",
        "@angular/core": "5.2.11",
        "@angular/forms": "5.2.11",
        "@angular/http": "5.2.11",
        "@angular/platform-browser": "5.2.11",
        "@angular/platform-browser-dynamic": "5.2.11",
        "@angular/router": "^4.3.5",
        "@ionic-native/android-permissions": "^4.11.0",
        "@ionic-native/calendar": "^4.17.0",
        "@ionic-native/call-number": "^4.17.0",
        "@ionic-native/camera": "^4.17.0",
        "@ionic-native/core": "^4.17.0",
        "@ionic-native/date-picker": "^4.20.0",
        "@ionic-native/device": "^4.18.0",
        "@ionic-native/email-composer": "^4.20.0",
        "@ionic-native/file": "^4.11.0",
        "@ionic-native/file-transfer": "^4.7.0",
        "@ionic-native/geolocation": "^4.17.0",
        "@ionic-native/google-maps": "^4.15.1",
        "@ionic-native/http": "^4.20.0",
        "@ionic-native/keyboard": "^4.11.0",
        "@ionic-native/native-geocoder": "^4.17.0",
        "@ionic-native/network": "^4.11.0",
        "@ionic-native/splash-screen": "4.7.0",
        "@ionic-native/sqlite": "^4.7.0",
        "@ionic-native/status-bar": "^4.12.1",
        "@ionic-native/text-to-speech": "^4.20.0",
        "@ionic-native/toast": "^4.11.0",
        "@ionic-native/transfer": "^3.14.0",
        "@ionic/storage": "2.1.3",
        "@ngx-translate/core": "^9.1.1",
        "@ngx-translate/http-loader": "^3.0.1",
        "@swimlane/ngx-charts": "^7.3.0",
        "@types/jspdf": "^1.2.1",
        "angular-progress-bar": "^1.0.8",
        "angular-svg-round-progressbar": "^2.0.0",
        "angular-translate": "^2.18.1",
        "angular-translator": "^2.4.2",
        "angular2-signature-pad": "^1.0.2",
        "angular2-signaturepad": "^2.8.0",
        "angular2-text-mask": "^9.0.0",
        "calendar": "^0.1.0",
        "call-number": "^1.0.1",
        "cordova-android": "7.0.0",
        "cordova-browser": "5.0.4",
        "cordova-pdf-generator": "^2.0.8",
        "cordova-plugin-advanced-http": "2.0.8",
        "cordova-plugin-android-permissions": "^1.0.0",
        "cordova-plugin-calendar": "^5.1.4",
        "cordova-plugin-camera": "^4.0.3",
        "cordova-plugin-compat": "^1.2.0",
        "cordova-plugin-datepicker": "^0.9.3",
        "cordova-plugin-device": "^2.0.2",
        "cordova-plugin-email-composer": "^0.9.2",
        "cordova-plugin-exit": "^1.0.2",
        "cordova-plugin-file": "^6.0.1",
        "cordova-plugin-file-transfer": "^1.7.1",
        "cordova-plugin-geolocation": "^4.0.1",
        "cordova-plugin-googlemaps": "^2.5.2",
        "cordova-plugin-ionic-keyboard": "^2.1.3",
        "cordova-plugin-ionic-webview": "^1.2.1",
        "cordova-plugin-iroot": "0.8.0",
        "cordova-plugin-nativegeocoder": "^3.1.3",
        "cordova-plugin-network-information": "^2.0.1",
        "cordova-plugin-root-detection": "^0.1.1",
        "cordova-plugin-splashscreen": "^5.0.2",
        "cordova-plugin-sslcertificatechecker": "6.0.0",
        "cordova-plugin-statusbar": "^2.4.2",
        "cordova-plugin-tts": "^0.2.3",
        "cordova-plugin-whitelist": "^1.3.3",
        "cordova-plugin-x-toast": "^2.7.2",
        "cordova-sqlcipher-adapter": "^0.4.0",
        "cordova-sqlite-storage": "^3.2.0",
        "cordova-uglify": "^0.3.3",
        "crypto-js": "^3.1.9-1",
        "html2canvas": "^1.0.0-alpha.12",
        "ionic-angular": "3.9.2",
        "ionic-select-searchable": "^2.10.0",
        "ionicons": "3.0.0",
        "jspdf": "^1.4.1",
        "moment": "^2.22.2",
        "mx.ferreyra.callnumber": "0.0.2",
        "ng2-bootstrap-modal": "^1.0.1",
        "ng2-currency-mask": "^5.3.1",
        "ngx-filter-pipe": "^2.1.0",
        "rasterizehtml": "^1.3.0",
        "run": "1.4.0",
        "rxjs": "5.5.11",
        "sw-toolbox": "3.6.0",
        "ts-md5": "^1.2.4",
        "uglify-es": "github:mishoo/UglifyJS2#harmony",
        "uglify-js": "^3.5.11",
        "zone.js": "0.8.26"
    },
    "devDependencies": {
        "@ionic/app-scripts": "3.1.10",
        "@types/jasmine": "^3.4.6",
        "javascript-obfuscator": "^0.18.1",
        "typescript": "~2.6.2"
    },
    "description": "An Ionic project",
    "cordova": {
        "plugins": {
        "cordova-plugin-device": {},
        "cordova-plugin-splashscreen": {},
        "cordova-plugin-ionic-webview": {},
        "cordova-plugin-ionic-keyboard": {},
        "cordova-plugin-whitelist": {},
        "cordova-plugin-x-toast": {},
        "cordova-plugin-network-information": {},
        "cordova-plugin-file-transfer": {},
        "cordova-plugin-android-permissions": {},
        "cordova-plugin-statusbar": {},
        "cordova-pdf-generator": {},
        "cordova-plugin-nativegeocoder": {},
        "cordova-plugin-camera": {},
        "mx.ferreyra.callnumber": {},
        "cordova-plugin-googlemaps": {
            "API_KEY_FOR_ANDROID": "AIzaSyAnaUfH593PQAmbmyFqv9ow3FKLfx4rXc",
            "API_KEY_FOR_IOS": "AIzaSyA-naUfH593PQAmbmyFqv9ow3FKLfx4rXc",
            "PLAY_SERVICES_VERSION": "15.0.1",
            "ANDROID_SUPPORT_V4_VERSION": "27.+"
        },
        "cordova-plugin-calendar": {},
        "cordova-plugin-datepicker": {},
        "cordova-plugin-tts": {},
        "cordova-plugin-geolocation": {
            "GEOLOCATION_USAGE_DESCRIPTION": "To locate you"
        },
        "call-number": {},
        "cordova-plugin-advanced-http": {},
        "cordova-plugin-iroot": {
            "ENABLE_BUSYBOX_CHECK": "true"
        },
        "cordova-plugin-sslcertificatechecker": {},
        "cordova-sqlcipher-adapter": {},
        "cordova-sqlite-storage": {}
        },
        "config": {
        "ionic_cleancss": "./config/cleancss.config.js"
        },
        "platforms": [
        "android",
        "browser"
        ]
    }
    }

如果我在 cpommand 提示符下运行 npm test 之类的命令(ag=安装 angular-cli 之后),我会得到以下错误

测试命令需要在 Angular 项目中运行,但找不到 ionic 项目定义。

由于我的项目已构建为 ionic-angular,因此它没有 angular.json 文件,我认为这是它未检测到 ng test/npm test 命令的原因。

请帮忙。谢谢。

编辑:

以下是我遇到的错误

【问题讨论】:

  • 您遇到了什么错误?提供这么多信息的解决方案是不可能的

标签: ionic3 angular7 karma-jasmine


【解决方案1】:

根据github下面的链接:

https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036

您必须进行转换:

尝试在终端中运行以下命令

ng update @angular/cli --migrate-only --from=1.7.4

【讨论】:

  • 谢谢。我会对此进行测试并通知您。
猜你喜欢
  • 2016-04-04
  • 1970-01-01
  • 2020-02-02
  • 1970-01-01
  • 2012-03-21
  • 2011-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多