Trying to make MULTIPLE mocked service response 500 for testing any suggestions?
Asked
Active
Viewed 1,172 times
1 Answers
3
Miragejs has a Response class which you can instantiate and return from your response handlers. The first argument in the constructor is the status:
import { Response } from 'miragejs';
this.get('/users', () => {
return new Response(500, { some: 'header' }, { errors: [ 'name cannot be blank'] });
});

Stefan Bajić
- 374
- 4
- 14
-
2I saw this in the docs as well but believe it or not I haven't been able to get it to work. It says the response is { "type": "default", "status": 200, "ok": true, "statusText": "", "headers": { "map": { "content-type": "text/plain;charset=UTF-8" } }, "url": "", "bodyUsed": false, "_bodyInit": 500, "_bodyText": "[object Number]" } – Jonathan Tuzman Jul 12 '22 at 20:27
-
1I had the same response with Jonathan, after adding the import it worked ! – bigiCrab Feb 07 '23 at 02:24