Questions tagged [http-mock]

22 questions
11
votes
1 answer

Configure CSP in an Ember CLI application which uses http-mock

I'm using http-mock with Ember CLI as suggested on http://www.ember-cli.com/#ember-data. I understand the basic concept of CSP but I don't understand the configuration of it within an Ember CLI application. How can I configure my application to…
wintermeyer
  • 8,178
  • 8
  • 39
  • 85
3
votes
1 answer

How to capture HTTP request and mock its response in Java?

Say that Java application makes requests to http://www.google.com/... and there's no way to configure the inherited library (making such requests internally), so I can not stub or replace this URL. Please, share some best practices to create a mock…
diziaq
  • 6,881
  • 16
  • 54
  • 96
3
votes
2 answers

Wiremock: choose body file name based on request parameter

I am using wiremock to mock http server and I am returning responses from json files (using withBodyFile method). Now I want to choose and return response json file based on request parameter. For the example below, I want to define one stub so that…
Kumar Gaurav
  • 729
  • 3
  • 9
  • 21
1
vote
0 answers

How to write unit tests for http server upgrade and handle connection to websocket server?

I have following class and methods - //A.ts export abstract class A { } // B.ts import http from 'http'; import { Socket } from 'net'; import url, { URL } from 'url'; import { Server as WebSocketServer } from 'ws'; import { authenticateToken } from…
1
vote
1 answer

Unable to run mockttp with Cypress

I'm trying to run the mockttp with cypress. I used the example that's listed in project github. I changed the port to run on 3000 but I am getting an error saying Cannot add rules before the server is started. /*global cy:true,before:true*/ ///…
cccap1550
  • 23
  • 4
1
vote
0 answers

How to mock a request in protractor

I have this mock module: exports.httpBackendMock = function() { angular.module('httpBackendMock', ['mainApp', 'ngMockE2E']) .run(function($httpBackend) { console.log('Test platform bootstrapping'); …
1
vote
1 answer

Testing async code in catch block using Nock or httpMock

I making a axios request which fails and throws error in catch block. In catch block I am making request to other end point to get results router.get('/info', (req, res) => { axios('www.getInformationApi.com') .then(results => { …
Mahesh
  • 221
  • 1
  • 3
  • 14
1
vote
2 answers

How to mock second try of http call?

As part of my first project I am creating a tiny library to send an SMS to any user. I have added the logic of waiting and retrying if it doesn't receive a positive status on first go. It's a basic HTTP call to am SMS sending service. My algorithm…
diwakarb
  • 543
  • 2
  • 9
  • 23
1
vote
1 answer

Testing Service : Difference between MockBackend method and spyOn().and.returnValue() method

These two tests seem to work (at least in my case) Do exist some specific differences between these two methods ? And how to decide the one I should use (best practices for testing service using Http) ? 1. Using MockBackend method beforeEach(() =>…
M'sieur Toph'
  • 2,534
  • 1
  • 21
  • 34
1
vote
2 answers

Ember save() throws JSON.parse error: "unexpected end of data at line 1 column 1 of the JSON data"

I have a model record created and being saved through a route and controller. When I save the record through the controller (via a savePlace action), I am seeing this error in the JS console: SyntaxError: JSON.parse: unexpected end of data at line 1…
allthesignals
  • 307
  • 2
  • 13
1
vote
1 answer

How to test active resource like models?

I am using a gem called spyke for my rails models. Spyke is similar to active resource and uses JSON API as data source. I want to write tests using rspec and factory girl. How can I set up a mock data source for testing? So far I have found…
0
votes
2 answers

What's the equivalent of the php Laravel's "Http::fake()" in Python/ Django / DRF / Pytest?

Laravel's Http:fake() method allows you to instruct the HTTP client to return stubbed / dummy responses when requests are made. How can I achieve the same using Django Rest Framework APIClient in tests? I tried requests_mock but it didn't yield the…
0
votes
1 answer

How to perform assertion for a Laravel test with a post request?

I am still very beginner in testing with the laravel framework. Because of this, I performed tests on the endpoints of my api, but for the post request I have problems with the methods assertOk(), assertStatus() and other it returns an error, but…
Serge
  • 50
  • 4
0
votes
0 answers

Error: Expected one matching request for criteria no parameters

I've found several answers to this problem, but all of them involve having parameters and not including them on the call. But my case is different because I do not have parameters. According to all the material, I have consulted, I cannot find what…
Nisanio
  • 4,056
  • 5
  • 34
  • 46
0
votes
0 answers

How to send dummy request for spying on method inside http.createServer listner?

I have a method as follows - // A.ts export abstract class A{ protected abstract method(); } //B.ts export class B extends A{ private _httpServer?: http.Server; private _wsServer?: WebSocketServer; constructor(){ super(); } …
1
2