0

このブログに基づいて Facebook ログイン ディレクティブを作成しています。

  app.directive('facebook', function($http) {
    return {
      restrict: 'A',
      scope: true,
      controller: function($scope, $attrs, $location) {
        // Load the SDK Asynchronously
        (function(d){
          var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
          if (d.getElementById(id)) {return;}
          js = d.createElement('script'); js.id = id; js.async = true;
          js.src = "//connect.facebook.net/en_US/all.js";
          ref.parentNode.insertBefore(js, ref);
        }(document));
    // ... the rest of the directive

この匿名関数を単体テストするにはどうすればよいですか? ドキュメントをモックしてもうまくいかないようです。

4

1 に答える 1

2

Facebook SDK を非同期的にロードしているため、基本的に運が悪いです。実際に自問すべき質問は、「何をテストしたいのか?」ということです。その質問が「facebook にログインする」である場合、実際には統合テスト ランナーを使用する必要があります。

http://docs.angularjs.org/guide/dev_guide.e2e-testing

于 2013-07-30T13:46:57.770 に答える