javascript - Angular Karma console.log 不起作用

标签 javascript angularjs karma-runner karma-mocha

我在我的项目中使用 Karma Angular Mocha Chai。我正在做 TDD 并想测试我的更改。我在我的 test.js 文件中做了一个 console.logkarma console 没有显示。我什至不确定如何启用它?

这是我的karma.config.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: ['mocha', 'chai'],


    // list of files / patterns to load in the browser
    files: [
      'src/main/webapp/js/angular.js',
      'src/main/webapp/js/angular-simple-logger.js',
      'src/main/webapp/js/services/myservice-test.js',
      'src/main/webapp/js/controllers/*.js',
      'src/test/webapp/**/*.js'
    ],

    // list of files to exclude
    exclude: [
    ],

    client : {
        captureConsole : true
    },

    // 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: ['Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  })
}

这是我的package.json:

{
  "name": "myapp",
  "version": "0.0.1",
  "description": "my App",
  "main": "src/main/webapp/index.html",
  "directories": {
    "doc": "docs"
  },
  "scripts": {
    "test": "node_modules/.bin/karma start karma.config.js"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "chai": "^3.5.0",
    "karma": "^0.13.22",
    "karma-chai": "^0.1.0",
    "karma-chrome-launcher": "^0.2.2",
    "karma-mocha": "^0.2.2",
    "mocha": "^2.4.5"
  },
  "dependencies": {
    "angular": "^1.5.1",
    "angular-mocks": "^1.5.1"
  }
}

最佳答案

添加

browserConsoleLogOptions: {
  level: 'log'
},

到你的config.set。这是对 karma 行为的新改进(karma 1.5.0,大约 2017-02-20)。请参阅此处的进一步讨论:https://github.com/karma-runner/karma/issues/2582

关于javascript - Angular Karma console.log 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36158998/

相关文章:

javascript - ng-repeat 中的 Angular 多复选框数组

javascript - 如何从列表中选择特定的列表项? (如第六个或第二个等)

javascript - 如何使用angularjs处理多页面网站?

javascript - 在 Angular JS 中做同样的更好的方法

html - 使用 Karma 生成 HTML 测试报告

javascript - grunt-karma RangeError 最大错误

ruby-on-rails - AngularJS 和 Rails - e2e 睾丸测试。如何登录用户来测试 Angular 页面?

javascript - 如何使用 JavaScript 使 SVG 缩放到父容器的全高和全宽?

javascript - 如何计算数组中以最高数字开头的项目数?

javascript - slot.value 返回所有话语,而不仅仅是来自 slot 的话语