Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for simulating empty body response #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ var server = new Pretender(function() {
});
```

You may return `null` or `undefined` instead of a string body, to simulate real-world responses:

```javascript
var server = new Pretender(function(){
this.get('/photos/:id/mark_favorite', function(request) {
return [
200,
{'content-type': 'application/json'},
null
];
});
});
```

### Pass-Through
You can specify paths that should be ignored by pretender and made as real XHR requests.
Enable these by specifying pass-through routes with `pretender.passthrough`:
Expand Down
31 changes: 30 additions & 1 deletion test/calling_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,34 @@ describe('pretender invoking', function(config) {

$.ajax({url: '/some/path'});
});
});

it('can return a null body response', function(assert) {
var done = assert.async();

this.pretender.get('/some/path', function(req) {
return [200, {'Content-Type': 'application/json'}, null];
});

this.pretender.handledRequest = function(verb, path, request) {
equal(request.responseText, '');
done();
};

$.ajax({url: '/some/path'});
});

it('can return an undefined body response', function(assert) {
var done = assert.async();

this.pretender.get('/some/path', function(req) {
return [200, {'Content-Type': 'application/json'}, undefined];
});

this.pretender.handledRequest = function(verb, path, request) {
equal(request.responseText, '');
done();
};

$.ajax({url: '/some/path'});
});
});