Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NodeJS,角形种子,吞咽,茉莉花,业力问题_Javascript_Node.js_Angularjs_Gulp_Karma Jasmine - Fatal编程技术网

Javascript NodeJS,角形种子,吞咽,茉莉花,业力问题

Javascript NodeJS,角形种子,吞咽,茉莉花,业力问题,javascript,node.js,angularjs,gulp,karma-jasmine,Javascript,Node.js,Angularjs,Gulp,Karma Jasmine,设置一个有角度的种子,我已经一切正常,我甚至可以启动jasmine浏览器,但由于某种原因,我的规范不起作用,所以我添加了一个karma.conf文件,它似乎破坏了jasmine浏览器。我刚开始使用Jasmine,所以我很茫然,对于如何最好地使用它,有很多意见,但无论我怎么尝试,我似乎都无法让它工作,我在这里为代码添加了repo链接。希望有人能看到我做错了什么 这个种子需要NodeJS 下载git,将其放入文件夹中 转到文件夹并在根目录中输入config文件夹 运行npm安装 然后运行gulp,它

设置一个有角度的种子,我已经一切正常,我甚至可以启动jasmine浏览器,但由于某种原因,我的规范不起作用,所以我添加了一个karma.conf文件,它似乎破坏了jasmine浏览器。我刚开始使用Jasmine,所以我很茫然,对于如何最好地使用它,有很多意见,但无论我怎么尝试,我似乎都无法让它工作,我在这里为代码添加了repo链接。希望有人能看到我做错了什么

这个种子需要NodeJS

下载git,将其放入文件夹中 转到文件夹并在根目录中输入config文件夹 运行npm安装 然后运行gulp,它将在浏览器中自动启动 在控制台中,您将看到此错误

[14:52:17] 'jasmineWeb' errored after 2.27 ms
[14:52:17] TypeError: object is not a function
    at Gulp.<anonymous> (/webdev/E20/config/gulpfile.js:137:11)
     at module.exports (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at /webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:279:18
at finish (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
at module.exports (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:60:3)
at Gulp.Orchestrator._runTask (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at /webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:279:18
这是我的Karma.conf文件

// Karma configuration
// Generated on Tue Jul 28 2015 11:28:22 GMT-0400 (EDT)

 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: [
       '../src/lib/js/angular/angular.min.js',
       '../src/lib/js/angular/angular-mocks.js',
       '../src/com/**/*.js',
       '../src/com/**/*_spec.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: ['Chrome', 'Firefox', 'IE', 'PhantomJS'],


     // Continuous Integration mode
     // if true, Karma captures browsers, runs the tests and exits
     singleRun: false
  })
} 
我提前表示感谢

因果报应正在运行,但我现在得到了这个错误

PhantomJS 1.9.8 (Mac OS X 0.0.0) Controller: com/modules/AboutController Sets the Page Message It should show the page message FAILED
    ReferenceError: Can't find variable: $scope
        at /webdev/E20/src/com/modules/about/aboutController_spec.js:15
Chrome 44.0.2403 (Mac OS X 10.10.4) Controller: com/modules/AboutController Sets the Page Message It should show the page message FAILED
    ReferenceError: $scope is not defined
        at Object.<anonymous> (/webdev/E20/src/com/modules/about/aboutController_spec.js:15:16)
Chrome 44.0.2403 (Mac OS X 10.10.4): Executed 1 of 1 (1 FAILED) ERROR (0.008 secs / 0.006 secs)
PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0 secs / 0.004 secs)

我运行茉莉花,因果报应,并使用一饮而尽,就像你做的。然而,在我如何启动它方面存在一些差异。也许这会对你有帮助

您的karma.config.js看起来很相似,因此可能没有问题

然而,在我的吞咽文件中,我称之为

gulp.task( 'karma', function( done ){
  karma.start({
    configFile: __dirname + '/karma.conf.js'
  }, done );
});

gulp karma
如果您还需要查看文件的更改,则可以运行此程序

var filesForTest = [ '../src/**/*.js' ];

gulp.task( 'watchOnSave', function(){
  gulp.watch( filesForTest, [ 'karma' ]);
}

gulp watchOnSave
karma.config.js文件将为您执行浏览器,并运行您在karma.config.js文件中定义的规格

  '../src/com/**/*_spec.js' // just make sure all your JS files are in your karma **files** property.
让我知道这是否有效,否则我们将讨论解决方案

更新

在你的应用程序(app.js)中,你有

var appName = 'EuropaSeed';

var globalApp = angular.module(appName,['ngRoute','ngCookies']);
var app = angular.module(appName);
在你的测试中

beforeEach(module('EuroSeed'));
您的问题之一是,您有两个名为EuroSeed的模块

app and globalApp
因此,在测试中,调用您需要的两个模块中的哪一个,如中所示

beforeEach(module(app));
与控制器中的内容相匹配

app.controller('AboutController',...
//This is the about function that is used in the About Module. 
    'use strict';
     app.controller('AboutController',// jshint ignore:line
        ['$scope',
        function ($scope) {
           $scope.message = 'This is the about page message from the controller';
        }]);
我用它来运行规范,它现在通过了,但没有使用except,因为要通过它还有另一个问题

吞咽文件

gulp.task('karma', function (done) {
  karma.server.start({ // had to add .server to karma
    configFile: __dirname + '/karma.conf.js'
  }, done);
});


它可能是规范,所以我想我会在这里发布规范和控制器,它们非常简单

现在,app.js文件中设置了“app”,因此应用程序本身可以工作

关于控制器

app.controller('AboutController',...
//This is the about function that is used in the About Module. 
    'use strict';
     app.controller('AboutController',// jshint ignore:line
        ['$scope',
        function ($scope) {
           $scope.message = 'This is the about page message from the controller';
        }]);
关于控制器测试

'use strict';

describe('Controller: com/modules/AboutController', function() {
  beforeEach(module('EuropaSeed'));

  var $controller;

  beforeEach(inject(function(_$controller_){
    // The injector unwraps the underscores (_) from around the parameter     names when matching
    $controller = _$controller_;
  }));

  describe('Sets the Page Message', function() {
    it('It should show the page message', function() {
        expect($scope.message).toEqual('This is the about page message from the controller');
    });

  });
});
我拉了我正在运行的测试,但我仍然在jasmineWeb上得到相同的错误,因此可能是配置错误

Europas-MacBook-Pro:config ray$ gulp jasmineWeb
[08:29:33] Using gulpfile /webdev/E20/config/gulpfile.js
[08:29:33] Starting 'jasmineWeb'...
[08:29:33] 'jasmineWeb' errored after 12 ms
[08:29:33] TypeError: object is not a function
    at Gulp.<anonymous> (/webdev/E20/config/gulpfile.js:137:11)
    at module.exports (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
    at node.js:814:3
Europas-MacBook-Pro:config ray$ 

在这里来回走动并得到一些人的帮助(非常感谢大家)之后,我找到了罪魁祸首,结果发现问题不在实际测试中,但在karma配置文件中,这是欺骗性的问题是我加载的bower组件,我没有加载足够的ng模拟,不足以对控制器进行测试,所以我添加了一些其他的模拟,它工作了,我能够让我的所有测试正常工作

下面是我在karma.conf文件部分添加的内容

'bower_components/angular/angular.js',
        'bower_components/angular-route/angular-route.js',
        'bower_components/angular-mocks/angular-mocks.js',
        'bower_components/angular-resource/angular-resource.js',
        'bower_components/angular-cookies/angular-cookies.js',
        'bower_components/angular-sanitize/angular-sanitize.js',
        '../src/com/**/*.js',
        '../src/com/**/*_spec.js'
我已经用新的工作代码更新了bitbucket种子,以满足那些想要更好示例的人的需要


bitbucket.org/baylysoft/angular seed project

这里是指向项目存储库的链接,以防需要更多信息。评论不用于扩展讨论;这段对话已经结束。
'use strict';

describe('Controller: com/modules/AboutController', function() {

    beforeEach(module(app));

    var AboutController,
        scope;

        beforeEach(inject(function ($rootScope, $controller) {
            scope = $rootScope.$new();
            AboutController = $controller('AboutController', {
                "$scope": scope
            });
        }));
    it('It should show the page message', function () {
        // you might also need to do this
        AboutController();
        expect(scope.greeting).toEqual("This is the about page message from the controller");
                                       });

    });
'bower_components/angular/angular.js',
        'bower_components/angular-route/angular-route.js',
        'bower_components/angular-mocks/angular-mocks.js',
        'bower_components/angular-resource/angular-resource.js',
        'bower_components/angular-cookies/angular-cookies.js',
        'bower_components/angular-sanitize/angular-sanitize.js',
        '../src/com/**/*.js',
        '../src/com/**/*_spec.js'