6

返されたデータが日付順にソートされていることを確認する必要があります。これは私がそれを書いている方法です:

it('should be sorted by date', function() {
    element.all(by.repeater('users in group.users')).then(
        function(users) {
            var lastUser = users[0].element(by.id('birth-date')).getText();
            for (var i = 1; i < users.length; ++i) {
                var currentUser = users[i].element(by.id('birth-date')).getText();
                expect(moment(currentApplication).format('MMM d, YYYY HH:mm')).toBeGreaterThan(moment(lastApplication).format('MMM d, YYYY HH:mm'));
                lastUser = currentUser;
            }
        }
    )
})

これは以下を返します:

Expected 'Jan 1, 2015 00:00' to be greater than 'Jan 1, 2015 00:00'.

私は何を間違っていますか?currentUser と lastUser は、テキストではなくオブジェクトのように見えます...しかし、その理由はわかりません。

4

3 に答える 3

8

を使用してすべての誕生日のリストを取得し、map()文字列のリストを日付のリストに変換して、同じ配列のソートされたバージョンと比較します。

element.all(by.id('birth-date')).map(function (elm) {
    return elm.getText().then(function (text) {
        return new Date(text);
    });
}).then(function (birthDates) {
    // get a copy of the array and sort it by date (reversed)
    var sortedBirthDates = birthDates.slice();
    sortedBirthDates = sortedBirthDates.sort(function(date1, date2) {
        return date2.getTime() - date1.getTime()
    });

    expect(birthDates).toEqual(sortedBirthDates);
});
于 2015-01-05T15:21:54.197 に答える