我有一个测试(使用AngularDart项目中的 Jasmine 语法)

describe("MockHttpBackend", () {

  beforeEach(() {
    setUpInjector();
    module((Module module) {
      module
      ..type(HttpBackend, implementedBy: MockHttpBackend);
      // ..value(HttpBackend, new MockHttpBackend()); // same problem
    });
  });

  it('should do basic request', async(inject((Http http, MockHttpBackend backend) {
    backend.expect('GET', '/url').respond('');
    http(url: '/url', method: 'GET');
  })));

导致
Test failed: Caught [Async error, [Unexpected request: GET /url No more requests expected],
#0 > MockHttpBackend.call (package:angular/mock/http_backend.dart:224:5)
#1 MockHttpBackend.request (package:angular/mock/http_backend.dart:137:9)

知道我在做什么错吗?

最佳答案

查看该代码段:

void mockTests() {
  describe("MockHttpBackend", () {

    TestBed _;
    Scope scope;
    Http http;
    MockHttpBackend backend;

    beforeEach(setUpInjector);
    beforeEach(module((Module m) {
      m.type(HttpBackend, implementedBy:MockHttpBackend);
    }));
    beforeEach(inject((TestBed tb) => _ = tb));
    beforeEach(inject((Scope s) => scope = s));
    beforeEach(inject((Http h) => http = h));
    beforeEach(inject((HttpBackend h) => backend = h));


    it('should do basic request', () {
      backend.expect('GET', '/url').respond('');
      http(url: '/url', method: 'GET');
    });
  });
}

那是你要找的东西吗

问候,
谢尔盖

关于dart - MockHttpBackend-意外的请求,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21881881/

10-10 17:56