【问题标题】:AngularJS $http testingAngularJS $http 测试
【发布时间】:2015-04-16 16:18:52
【问题描述】:

是否可以在不模拟的情况下使用 $http ?发出调用的服务:

// Make the request we are interested in testing
ViewingRepositoryService.getThumbnail(obj, "urn:adsk.wipdata:versionedFile:BQLHHmlCRd-bqnr8rxF2xA?version=1", "medium")
    .then(function (data) { // On success (this is what we are expecting)
        console.log('success');
        expect(data).to.deep.equal(mockData); //Validate the data is correct
        done();
    },
    function (err) {
        console.log('error');
        done();
    }
);

不显示“成功”或“错误”。

【问题讨论】:

  • 只看到这个,什么也说不出来。在此处发布您的详细代码。 ViewingRepositoryService 中有什么?
  • 我认为您的服务功能看起来很奇怪。我也不是很喜欢服务,但也许这tutorial 有帮助。你可以用wireshark查看网络传输
  • 你能解决你的问题吗?

标签: javascript angularjs angularjs-http


【解决方案1】:

你可以看看这个帖子:Write tests for an angular REST app

您需要在测试文件中包含 angular-mocks-with-real-backend.js,然后像往常一样使用 $http。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-29
    • 2014-01-10
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    相关资源
    最近更新 更多