11
$httpBackend.whenGET('/restpath/api/v1/books')
.respond({// some data}); 

次のエラーが表示されます

Error: Unexpected request: GET /restpath/api/v1/books
 Expected GET /restpath/api/v1/books?limit=10&start=1

expectGET の場合、次のものがあります。これにより、動的クエリ文字列が作成されます。主に「開始」パラメーターと whenGET 部分で、「開始」に応じて動的コンテンツをサーバーに送信しようとしています。

$httpBackend.expectGET('/restpath/api/v1/books?limit=10&start=1'); // the actual service goes here , which does the $http service. we don't care $httpBackend.flush();

4

3 に答える 3

23

(バージョンが v1.5.0-build.4371 よりも低い角度のアプリの場合)

「?」の後のパラメーターを気にしない場合 あなたはこれを行うことができます :

$httpBackend.expectGET(/.*?restpath\/api\/v1\/books?.*/g).respond(200, '{}');

最初のパラメーターが気になる場合は、次のようにします。

$httpBackend.expectGET(/.*?restpath\/api\/v1\/books?limit=10.*/g).respond(200, '{}');

あなたがそれらすべてを気にするなら、これをしてください:

$httpBackend.expectGET("/restpath/api/v1/books?limit=10&start=1").respond(200, '{}');
于 2015-08-14T09:48:55.203 に答える
3

の引数

whenGET('/restpath/api/v1/')

expectGET('restpath/api/v1/books?limit=10&start=1')

異なっています。それらは同じでなければなりません。

于 2015-08-14T07:10:31.713 に答える