bower_components / angular / angular.js,foreach @ bower_components错误karma angular 1.5

时间:2017-07-25 00:09:46

标签: angularjs jasmine karma-jasmine bower

当我在spec文件中使用$ inject时,我收到以下错误。

我在karma.conf.js中添加了bower.json的所有依赖项。

请帮我在spec.js文件中使用$ inject

app.js:

export default {
  Query: {
    allLinks: async (root, data, { mongo: { Links } }) =>
      Links.find({}).toArray()
  },
  Mutation: {
    createLink: async (root, data, { mongo: { Links }, user }) => {
      const newLink = Object.assign({ postedById: user && user._id }, data);
      const response = await Links.insert(newLink);
      return Object.assign({ id: response.insertedIds[0] }, newLink);
    },
    createUser: async (root, data, { mongo: { Users } }) => {
      const newUser = {
        name: data.name,
        email: data.authProvider.email.email,
        password: data.authProvider.email.password
      };
      const response = await Users.insert(newUser);
      return Object.assign({ id: response.insertedIds[0] }, newUser);
    },
    signinUser: async (root, data, { mongo: { Users } }) => {
      const user = await Users.findOne({ email: data.email.email });
      if (data.email.password === user.password) {
        return { token: `token-${user.email}`, user };
      }
    }
  },

  Link: {
    id: root => root._id || root.id,
    postedBy: async ({ postedById }, data, { dataloaders: { userLoader } }) => {
      return await userLoader.load(postedById);
    }
  },
  User: {
    id: root => root._id || root.id
  }
};

spec.js:

(function () {
    'use strict';

    angular
        .module('modulename', [
            'app.vegetation'
        ]);
})();

Karma.conf.js

describe("Basic Test", function () {
    beforeEach(module('modulename'));
    beforeEach(module('app.vegetation'));

    beforeEach(angular.mock.inject(function (_$controller_) {
        //scope = $rootscope.$new();
        //mainctrl = $controller('ProjectDetailsController', { $scope: scope });
        //$scope.password = 'longerthaneightchars';
        //$scope.grade();
    }));

    it("contains spec with an expectation", function () {
        expect(true).toBe(true);
    });
});

Bower.json:

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: [
            'bower_components/jquery/dist/jquery.js',
            'bower_components/angular/angular.js',
            'bower_components/angular-loading-bar/build/loading-bar.js',
            'bower_components/angular-ui-router/release/angular-ui-router.js',
            'bower_components/angular-route/angular-route.js',
            'bower_components/angular-bootstrap/ui-bootstrap.js',
            'bower_components/angular-bootstrap/ui-bootstrap.min.js',
            'bower_components/angular-cookies/angular-cookies.js',
            'bower_components/angular-animate/angular-animate.js',
            'bower_components/angular-ui-utils/index.js',
            'bower_components/oclazyload/dist/ocLazyLoad.js',
            'bower_components/slimScroll/jquery.slimscroll.min.js',
            'bower_components/ngstorage/ngStorage.js',
            'bower_components/modernizr/modernizr.custom.js',
            'bower_components/angular-sanitize/angular-sanitize.js',
            'bower_components/angular-resource/angular-resource.js',
            'bower_components/angular-touch/angular-touch.js',
            'bower_components/jquery.browser/dist/jquery.browser.js',
            //'bower_components/angular-ui-map/ui.map.js',
            'bower_components/angular-material/angular-material.js',
            'bower_components/angular-aria/angular-aria.js',
            'bower_components/angular-messages/angular-messages.js',
            'bower_components/angular-mocks/angular-mocks.js',
            'app/**/*.module.js',
            'app/js/app.js',
            'app/js/*.js',
            'app/js/vegetation/projectdetails/projectdetails.controller.js',
            'test/*.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: ['PhantomJS'],

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

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

ERROR

  "dependencies": {
    "angular-loading-bar": "0.8.0",
    "angular-ui-router": "0.2.18",
    "angular": "1.5.0",
    "angular-route": "1.5.0",
    "angular-bootstrap": "1.1.2",
    "angular-cookies": "1.5.0",
    "angular-animate": "1.5.0",
    "angular-ui-utils": "3.0.0",
    "fontawesome": "4.5.0",
    "oclazyload": "1.0.9",
    "slimScroll": "1.3.7",
    "ngstorage": "0.3.10",
    "jquery": "2.2.1",
    "modernizr": "https://modernizr.com/download?backgroundsize-bgpositionshorthand-bgpositionxy-bgrepeatspace_bgrepeatround-bgsizecover-borderradius-cssanimations-csscalc-csstransforms-csstransforms3d-csstransitions-flexboxtweener-fontface-inlinesvg-localstorage-multiplebgs-preserve3d-sessionstorage-smil-svgclippaths-svgfilters-svgforeignobject-todataurljpeg_todataurlpng_todataurlwebp-setclasses&q=background.zip",
    "angular-sanitize": "1.5.0",
    "angular-resource": "1.5.0",
    "simple-line-icons": "2.2.3",
    "angular-touch": "1.5.0",
    "jquery.browser": "master",
    "angular-ui-map": "0.5.0",
    "weather-icons": "2.0.10",
    "angular-material": "1.0.5",
    "angular-aria": "1.5.0",
    "angular-messages": "1.5.0",
    "angular-file-upload": "2.2.0",
    "angular-mocks": "1.5.0"
  },
  "resolutions": {
    "angular": "1.5.0",
    "angular-ui-utils": "3.0.0"
  }

0 个答案:

没有答案