【问题标题】:How to write behavioral/functional/endpoint tests using Angular and Jasmine + $resource?如何使用 Angular 和 Jasmine + $resource 编写行为/功能/端点测试?
【发布时间】:2014-06-05 20:41:17
【问题描述】:

我想编写服务器端点的功能测试。我不做 e2e 测试。这更像是一种功能/行为测试。

    beforeEach(inject(function ($injector) {
        f = $injector.get('WidgetFactory');
    }));

    it('should have a factory and get all widgets',inject(function($timeout ){
       expect(f).toBeDefined();
       expect(f).toBeTruthy();

       var qArray = f.query();

       $timeout.flush()

       expect(qArray.length).toBe(3);
    }));

但是,jasmine 会产生这个错误:

unexpected request: GET http://some.made.up.service:8080/widget/ 
No more request expected

想用httpBackend.whenGET() 模拟它,我想实际测试我的端点是否存在不良行为(也就是责怪后端团队)。我模拟响应的单元测试是一个单独的规范文件。

茉莉花有什么办法吗?我不想也必须添加量角器或摩卡咖啡。

【问题讨论】:

    标签: angularjs unit-testing jasmine functional-testing angular-mock


    【解决方案1】:

    所以我猜你正在寻找 api 端点测试框架。 Frisby (http://frisbyjs.com/docs/api/) 非常适合。它基于 nodejs 和 jasmine 来测试端点。

    【讨论】:

      猜你喜欢
      • 2020-11-28
      • 2018-01-31
      • 2018-10-16
      • 1970-01-01
      • 2015-12-09
      • 2020-02-18
      • 2019-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多