对startAt end的单元测试时间戳查询错误的结果

时间:2017-11-24 09:33:47

标签: javascript unit-testing firebase jasmine

我正在尝试使用angularfire从firebase检索数据时进行一些单元测试。

这是我的测试功能:

function panelsByCompleted(firstDay, lastDay){
  var panels = firebase.database().ref().child("panels").orderByChild("qa/completed").startAt(firstDay).endAt(lastDay); 
  return $firebaseArray(panels);
}

这是测试:

describe("panelsByCompleted", function () {

        var startedTimestamp = 1509494400;
        var completedTimestamp = 1512086340;

        var panel1 = {
          id: "panel1",
          area: "PROJ1AREA1",
          qa: {
            completed: 1510380000
          }
        };

        var panel2 = {
          id: "panel2",
          area: "PROJ1AREA1",
          qa: {
            completed: 1511164800
          }
        };
        //11/21/2017 @ 4:00pm (UTC)
        var panel3 = {
          id: "panel3",
          area: "PROJ1AREA2",
          qa: {
            completed: 1511280000
          }
        };

        beforeEach(function () {
          panelsRef.set({
            "PROJ1AREA1PANEL1": panel1,
            "PROJ1AREA1PANEL2": panel2,
            "PROJ1AREA2PANEL1": panel3
          });
        });

        it("returns all panels completed in date range", function () {
          var result = panelsService.panelsByCompleted(startedTimestamp, completedTimestamp);

          scope.$apply();
          expect(result.length).toEqual(3);
          expect(result[0]).toEqual(jasmine.objectContaining(panel1));
          expect(result[1]).toEqual(jasmine.objectContaining(panel2));
          expect(result[2]).toEqual(jasmine.objectContaining(panel3));
        });
      });

result.length等于0,它应该得到result.length等于3.

任何想法都错了吗?

0 个答案:

没有答案