Angularjs 业力:无法读取属性';风格';未定义的

Angularjs 业力:无法读取属性';风格';未定义的,angularjs,jasmine,karma-runner,Angularjs,Jasmine,Karma Runner,我试图使用karma对Angularjs代码进行单元测试。 这是我的conf文件: 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/b

我试图使用karma对Angularjs代码进行单元测试。 这是我的conf文件:

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: [
  'http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js',
  'https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js',
  'https://code.angularjs.org/1.2.26/angular-mocks.js',
  'test/unit/**/*.js',
  'js/app.js',
  'js/controllers/AffairesCtrl.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_DEBUG,


// 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
});
};
我正在测试一个具有以下代码的函数:

document.getElementById('case').style.display="none";
运行测试时,出现以下错误:

TypeError: Cannot read property 'style' of undefined
但是,如果我用jQuery代码替换javascript代码:

$("#case").css("display","none");
然后,测试成功,之前的错误消失

你知道我为什么会犯这个错误吗


谢谢大家!

可能是因为您的文档没有id为“case”的元素

请参阅上的文档

另一方面,如果不存在元素,jQuery不会返回null。因此没有错误