2

humane.js 通知ライブラリを AngularJS アプリに組み込もうとしています。humane.js の使用を Angular サービスにラップしましたが、アプリは正しく動作しています。しかし、Angular サービスの単体テストを作成しようとすると、このサービスの最初のテストを実行しようとすると、次のエラーが発生します。

ReferenceError: humane is not defined

私の karma.conf ファイルには、humane.js ファイルへの参照が含まれています。

files: [
  'bower_components/angular/angular.js',
  'bower_components/angular-route/angular-route.js',
  'bower_components/angular-mocks/angular-mocks.js',
  'bower_components/messageformat/messageformat.js',
  'bower_components/angular-translate/angular-translate.js',
  'bower_components/angular-translate-interpolation-messageformat/angular-translate-interpolation-messageformat.js',
  'bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.js',
  'bower_components/momentjs/moment.js',
  'other_components/highcharts-ng/src/directives/highcharts-ng.js',
  'other_components/keylines/keylines.js',
  'other_components/logging/log4javascript.js',
  'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
  'bower_components/humane-js/humane.js',
  'scripts/*.js',
  'scripts/*/*.js',
  'resources/defaultTranslations.js',
  'test/unit/*/*.js',
  'views/*.html'
],

何が問題なのかわかりません。Humane.js を同様の通知ライブラリ ( alertify.js ) に置き換えて、まったく同じことを行っても、エラーは発生しません。

私は何が欠けていますか?私が言ったように、アプリケーションは通知部分を含めて機能します。単体テストのみが影響を受けます。Humane.js モジュールは、(私にとっては) 変わった自己実行モジュール構文を使用しています。

;!function (name, context, definition) {
  if (typeof module !== 'undefined') module.exports = definition(name, context)
  else if (typeof define === 'function' && typeof define.amd  === 'object') define(definition)
  else context[name] = definition(name, context)
}('humane', this, function (name, context) {

...モジュール定義はこちら...

   return new Humane()
})

これがどういうわけかカルマローダーを混乱させているのではないかと思っています。他のライブラリ (alertify.js) にはこの構造はありません。

4

1 に答える 1