Angularjs 如何在使用角度数据模拟时调用DS.find().then()

Angularjs 如何在使用角度数据模拟时调用DS.find().then(),angularjs,jasmine,sinon,angular-data,Angularjs,Jasmine,Sinon,Angular Data,我一直在尝试测试我正在编写的一个服务,该服务使用角度数据存储,但无法让它调用传递给then()的回调。我有一个基本的例子来说明我在下面要做什么,以及我期望发生什么。有谁能解释一下我做错了什么,以及为什么这不符合预期 我希望这个测试能够通过,并将它打印到控制台。两者都没有,失败的原因是“预期假为真” 好的,我们已经解决了,我们需要在预期之前调用DS.flush()。这就是实际触发要调用的回调的原因 describe('usage of expectFind', function(){ before

我一直在尝试测试我正在编写的一个服务,该服务使用角度数据存储,但无法让它调用传递给
then()
的回调。我有一个基本的例子来说明我在下面要做什么,以及我期望发生什么。有谁能解释一下我做错了什么,以及为什么这不符合预期

我希望这个测试能够通过,并将它打印到控制台。两者都没有,失败的原因是“预期假为真”


好的,我们已经解决了,我们需要在预期之前调用
DS.flush()
。这就是实际触发要调用的回调的原因

describe('usage of expectFind', function(){
beforeEach(function (done) {
    inject(function (_DS_) {
        DS = _DS_;
        done();
    });
});

it('should call the callback passed to then', function(done){
    DS.expectFind('foo', 1).respond([{a: 'thing'}])

    var called = false;
    DS.find('foo', 1).then(function(aFoo){
        console.log('this is called');
        called = true;
        done();
    });


    // this is what's missing
    DS.flush();

    expect(called).toBe(true);
});

}))

另外,我尝试用
angular data mocks
标记添加这个,但它不存在,而且我没有足够的rep来创建它,如果有人可以添加它,那就太好了。
describe('usage of expectFind', function(){
beforeEach(function (done) {
    inject(function (_DS_) {
        DS = _DS_;
        done();
    });
});

it('should call the callback passed to then', function(done){
    DS.expectFind('foo', 1).respond([{a: 'thing'}])

    var called = false;
    DS.find('foo', 1).then(function(aFoo){
        console.log('this is called');
        called = true;
        done();
    });


    // this is what's missing
    DS.flush();

    expect(called).toBe(true);
});