0

私は「Smart Table」を使用しており、チェックボックスがテーブル内の行を選択するサンプルプラグインを使用します: http://lorenzofox3.github.io/smart-table-website/#section-custom

このディレクティブの単体テストを書いています。以下のコードは失敗しています。誰かがこのコードの単体テストを書いたことがありますか、または私がどこで間違っているのか、そして実際に正しいロジックをテストしているかどうかを教えてくれますか?

指令:

myApp.directive('csSelect', function () {
    return {
        require: '^stTable',
        template: '',
        scope: {
            row: '=csSelect'
        },
        link: function (scope, element, attr, ctrl) {

            element.bind('change', function (evt) {
                scope.$apply(function () {
                    ctrl.select(scope.row, 'multiple');
                });
            });

            scope.$watch('row.isSelected', function (newValue, oldValue) {
                if (newValue === true) {
                    element.parent().addClass('st-selected');
                } else {
                    element.parent().removeClass('st-selected');
                }
            });
        }
    };
});

単体テスト:

 describe('csSelect',function(){
        var scope, element, attr, ctrl;
       beforeEach(module('myApp.selectorresult'));
             beforeEach(inject(function($rootScope, $compile) {
                elm = angular.element(
                    '<td cs-select="row" class="ng-isolate-scope">' +
                    '<input type="checkbox">' +
                    '</td>');
                scope = $rootScope;
                $compile(elm)(scope);
                scope.$digest();
              }));
       it('should create selectable input',function(){
            console.log(elm.find('input'));
            var checkbox = elm.find('input');
            expect(checkbox.length).toBe(1);
      });
    });
4

2 に答える 2

0

beforeEach(inject... を設定する前に $controllerProvider で stTableController をモックアウトする必要があります。

ページネーション ディレクティブ ( https://github.com/lorenzofox3/Smart-Table/blob/master/test/spec/stPagination.spec.js ) のテスト仕様を確認してください。これには「stTable」も必要です。これは、「stTableController」に必要な機能を提供する方法の良い例です。

于 2015-04-24T22:05:46.550 に答える