首页 > 解决方案 > 我一直在尝试在 nativescript 应用程序中运行一些单元测试,但它抛出了 typeError Cannot set property '_moduleName' of undefined

问题描述

我花了几天时间尝试在我的 nativescript 应用程序上运行示例单元测试,但测试没有运行。当我执行命令时

tns run android

该应用程序运行良好。

错误只是在我运行时发生

tns test android

更多信息

"dependencies": {
    "nativescript-theme-core": "~1.0.4",
    "nativescript-unit-test-runner": "^0.7.0",
    "tns-core-modules": "~5.3.0"
  },
  "devDependencies": {
    "@types/karma-chai": "0.1.1",
    "@types/mocha": "5.2.6",
    "chai": "4.2.0",
    "karma": "4.3.0",
    "karma-chai": "0.1.0",
    "karma-mocha": "1.3.0",
    "karma-nativescript-launcher": "0.4.0",
    "karma-webpack": "3.0.5",
    "mocha": "6.1.4",
    "nativescript-dev-typescript": "~0.9.0",
    "nativescript-dev-webpack": "~0.21.0"
  }

这是测试示例

describe('Array', function () {
    describe('#indexOf()', function () {
        it('should return -1 when the value is not present', function () {
            assert.equal(-1, [1, 2, 3].indexOf(5));
            assert.equal(-1, [1, 2, 3].indexOf(0));
        });
    });
})

这是错误日志

Found peer TypeScript 3.1.6
07 09 2019 14:42:33.089:INFO [filelist]: Changed file "/home/jnovas/NativescriptProj/nativescript-app/demo/app/tests/example.js".
07 09 2019 14:42:33.343:WARN [karma]: No captured browser, open http://localhost:9876/
Preparing project...
Project successfully prepared (Android)
Installing on device emulator-5554...
Successfully installed on device with identifier 'emulator-5554'.
Restarting application on device emulator-5554...
Successfully synced application org.nativescript.demo on device emulator-5554.
System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.demo/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
System.err: Calling js method onCreate failed
System.err: 
System.err: TypeError: Cannot set property '_moduleName' of undefined
System.err: File: "file:///data/data/org.nativescript.demo/files/app/tns_modules/tns-core-modules/ui/builder/builder.js, line: 111, column: 30
System.err: 
System.err: StackTrace: 
System.err:     Frame: function:'markAsModuleRoot', file:'file:///data/data/org.nativescript.demo/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 111, column: 31
System.err:     Frame: function:'loadPage', file:'file:///data/data/org.nativescript.demo/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 55, column: 5
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.demo/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 74, column: 12
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.demo/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 88, column: 20
System.err:     Frame: function:'ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.demo/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 935, column: 42
System.err:     Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.demo/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 768, column: 14
System.err:     Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.demo/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
System.err: 
System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)

有人遇到同样的错误吗?

标签: androidnativescript

解决方案


推荐阅读