茉莉花注射不起作用

时间:2016-05-12 14:22:23

标签: angularjs typescript jasmine karma-runner browserify

所以我有一个1.5角应用程序,我用Typescript编译,然后通过Browserify捆绑它。

现在,当我想用​​Karma和Jasmine测试它时,我想在注入服务后立即收到错误(在启用了strict-di的浏览器中它可以正常工作)。

有人看到错误的位置吗?

CacheServiceTest.ts

import {CacheService} from "../../../app/services/CacheService";
import {Application} from "../../../app/Application";

describe("AppComponent", () => {
    beforeEach(() => {
        angular.mock.module(Application.name);
    });

    it("should contain CacheService", () => {
        inject((CacheService:CacheService) => {
            console.log(CacheService);
        });
    });
});

Karma config

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", "browserify"],

        // list of files / patterns to load in the browser
        files: [
            "node_modules/angular/angular.js",
            "node_modules/angular-mocks/angular-mocks.js",
            "node_modules/ngLeague/dist/ngLeague.js",
            "node_modules/angular-localforage/dist/angular-localForage.js",
            "app/**/*.ts",
            "tests/unit/**/*.ts",

            // JSON fixture
            {
                pattern:  "tests/fixtures/**/*.json",
                watched:  true,
                served:   true,
                included: false
            }
        ],

        // 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: {
            "app/**/*.ts": ["browserify", "ng-annotate"],
            "tests/unit/**/*.ts": ["browserify", "ng-annotate"],
            "dist/ngCache.js": "coverage"
        },

        // Browserify config
        browserify: {
            debug: true,
            plugin: [
                ["tsify", {target: "ES5"}]
            ]
        },

        // test results reporter to use
        // possible values: "dots", "progress"
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        reporters: ["progress", "coverage"],

        coverageReporter: {
            type : "html",
            dir : "tests/coverage/"
        },

        // 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: false
    });
};

错误

forEach@/home/kme/Documents/ngCache/node_modules/angular/angular.js:322:24
    loadModules@/home/kme/Documents/ngCache/node_modules/angular/angular.js:4548:12
    createInjector@/home/kme/Documents/ngCache/node_modules/angular/angular.js:4470:30
    workFn@/home/kme/Documents/ngCache/node_modules/angular-mocks/angular-mocks.js:2954:60
    inject@/home/kme/Documents/ngCache/node_modules/angular-mocks/angular-mocks.js:2934:46
    /tmp/fe42636aeb0f927c8dcd9afa7c80f051.browserify:16447:15 <- tests/unit/services/CacheServiceTest.ts:14:15
    /home/kme/Documents/ngCache/node_modules/angular/angular.js:4588:53

1 个答案:

答案 0 :(得分:-4)

localforage没有加载,嗯..