1

AngularJS TODO MVC アプリケーションの単体テストを作成しようとしていますが、e2e テスト構文の学習に少し行き詰まっています。

これまでのところ、ここに私が持っているものがあります:

describe('todomvc', function () {

    beforeEach(function () {
        browser().navigateTo('../app/index.html');
    });

    afterEach(function() {
        localStorage.clear();
    });

    describe('localstorage behavior', function() {
        it('should load with zero items in localstorage', function() {
            expect(repeater('#todo-list li').count()).toEqual(0);
            input('newTodo').enter('Foo Bar');
            expect(repeater('#todo-list li').count()).toEqual(1);
        });
    });

});

そして私の設定:

basePath = '../';

files = [
  ANGULAR_SCENARIO,
  ANGULAR_SCENARIO_ADAPTER,
  'test/e2e/**/*.js'
];

autoWatch = false;

browsers = ['Chrome'];

//singleRun = true;

proxies = {
  '/': 'http://localhost:8000/'
};

junitReporter = {
  outputFile: 'test_out/e2e.xml',
  suite: 'e2e'
};

つまり、「Enter」キーをシミュレートする方法が必要です。これは、この TODO MVC アプリが項目をリストに追加する方法だからです。これどうやってするの?

4

2 に答える 2

1

次のようにクラス属性をフォームに追加できます

<form class="myForm">

このステップをテストファイルに追加します

element(':form.myForm').submit();

これはうまくいくかもしれないと思います。

于 2013-08-17T11:47:01.170 に答える
0

jQuery を少し使用して、「Enter」キーをトリガーすることができます。これが機能するように、設定ファイルで jQuery ライブラリをリンクすることを忘れないでください。

describe('localstorage behavior', function() {
    it('should load with zero items in localstorage', function() {
        var e = jQuery.Event("keydown", {
            keyCode: 13
        });

        expect(repeater('#todo-list li').count()).toEqual(0);
        input('newTodo').enter('Foo Bar');

        element = angular.element('<input name="mytext" type="text" ng-model="mytext">');
        element = compile(element)(scope);

        element.trigger(e);
        scope.$digest();

        expect(repeater('#todo-list li').count()).toEqual(1);
    });
});
于 2015-03-02T07:16:34.120 に答える