【发布时间】:2016-05-05 09:13:01
【问题描述】:
在我的 Angular2 和 NativeScript 项目中使用 Karma 和 Jasmine 运行测试时遇到以下错误。测试正在正确执行,但是,此错误在控制台中不断重复。我观察到错误仅在导入 zone.js 后出现(导入它是因为它说在使用 Angular2/testing 的注入等时未定义区域)。
错误:
JS: NSUTR-socket.io: transport error JS: NSUTR-socket.io: 1 JS: NSUTR: socket.io error on connect: Error: xhr poll error JS: NSUTR-socket.io: 2 JS: NSUTR: socket.io error on connect: Error: xhr poll error 04 05 2016 12:33:42.046:WARN [NativeScript / 23 (6.0; Google Nexus 6P -
6.0.0 - API 23 - 1440x2560)]: D isconnected (1 times), because no message in 10000 ms.
JS: NSUTR-socket.io: 3 JS: NSUTR: socket.io error on connect: Error: xhr poll error JS: NSUTR-socket.io: 4 JS: NSUTR: socket.io error on connect: Error: xhr poll error
我的规范(测试)文件:
import 'reflect-metadata';
import 'zone.js/dist/zone.min.js';
import {Home} from '../components/home/home';
import {inject, beforeEachProviders, it, describe, expect} from 'angular2/testing';
beforeEachProviders(() => [Home]);
describe('Home Page ActionBar Title Test', () => {
// it('Title has text', () => {
it('Title has text', inject([Home], (homeObj: Home) => {
expect(homeObj.title).toBe('CapacityReview');
// expect(true).toBe(true);
}));
});
Package.json:
"dependencies": {
"angular2": "2.0.0-beta.16",
"es6-shim": "0.35.0",
"nativescript-angular": "0.0.46",
"nativescript-intl": "0.0.2",
"nativescript-unit-test-runner": "^0.3.3",
"parse5": "1.4.2",
"punycode": "1.3.2",
"querystring": "0.2.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"tns-core-modules": "2.0.0",
"url": "0.10.3",
"zone.js": "0.6.12"
},
"devDependencies": {
"babel-traverse": "6.7.6",
"babel-types": "6.7.7",
"babylon": "6.7.0",
"filewalker": "0.1.2",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-jasmine": "^0.3.8",
"karma-nativescript-launcher": "^0.4.0",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.1",
"typescript": "^1.8.10"
}
karma.conf.js(默认): >
module.exports = function(config) { config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['jasmine'], // list of files / patterns to load in the browser files: [ 'app/**/*.js' ], // list of files to exclude exclude: [ ], // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { }, // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter reporters: ['progress'], // web server port port: 9876, // enable / disable colors in the output (reporters and logs) colors: true, // level of logging // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG logLevel: config.LOG_INFO, // enable / disable watching file and executing tests whenever any file changes autoWatch: true, // start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: [], customLaunchers: { android: { base: 'NS', platform: 'android' }, ios: { base: 'NS', platform: 'ios' }, ios_simulator: { base: 'NS', platform: 'ios', arguments: ['--emulator'] } }, // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits singleRun: false }) }
【问题讨论】:
标签: android socket.io angular karma-jasmine nativescript