Angular2 Jasmine spyOn http调用

时间:2017-03-29 14:40:57

标签: angular jasmine angular2-http angular2-testing

我想监视 names = ["Asia","Łukasz","Aneta","Ola","Mikołaj"] wages = [15000,1500,200,14500,2600] the_dict = {} for i in range(len(names)): the_dict[wages[i]] = names[i] wages.sort() sorted_names = [the_dict[i] for i in wages] #now, both names and wages are sorted, and you can print them for i in range(len(wages)): print(sorted_names[i], wages[i]) 服务,看看它是否调用了正确的端点。有可能吗?

到目前为止,在我的服务中,我所有的测试都是他们发回数据......我想让它们更有用。

如果您需要它,这是我当前的spec文件:

Http

1 个答案:

答案 0 :(得分:4)

几乎就在那里!只需在mockBackend声明中添加expect即可。

示例:

    mockBackend.connections.subscribe(connection => {

      // Check if it invokes a http POST call
      expect(connection.request.method).toBe(RequestMethod.Post);

      // Check if the URL is correct
      expect(connection.request.url).toBe('/some-url');

      connection.mockRespond(new Response(new ResponseOptions({
        body: JSON.stringify(''),
        status: 200
      })));

    });