Fake Server is a bridge between Jasmine and Sinon. It provides a simplified interface for mocking ajax requests with Sinon's fakeServer when writing tests with Jasmine.
JavaScript
Switch branches/tags
Nothing to show
Latest commit 286ae6f Oct 30, 2012 @craigmaslowski updated docs again
Permalink
Failed to load latest commit information.
tests initial commit Jul 11, 2012
.gitignore initial commit Jul 11, 2012
README.md updated docs again Oct 30, 2012
fake.server.js initial commit Jul 11, 2012

README.md

FakeServer

Fake Server is a bridge between Jasmine and Sinon which provides a simplified interface for creating and mocking ajax requests when writing tests with Jasmine.

// Create the fake server
var server = new FakeServer();

// Setup routes
server.routes([
	{
		url: '/myRoute',
		headers: {
			'Content-Type': 'text/html',
			'Custom-Header': 'Custom-Header-Value'
		},
		body: '<p>some html</p>'
	}
]);

describe('myRoute', function () {
	var response, jqXHR;

	beforeEach(function () {
		$.ajax({
			url: '/myRoute',
			success: function (resp, textStatus, jqxhr) {
				response = resp;
				jqXHR = jqxhr;

				// let FakeServer know the ajax call is complete
				server.complete();
			},
			error: {
				jqXHR = jqxhr;

				// let FakeServer know the ajax call is complete
				server.complete();
			}
		});
	});
	
	afterEach(function () {
		response = undefined;
		jqXHR = undefined;
	});

	it('should return some html', function () {
		// Test the response once the ajax call is completed
		server.respond(function () {
			expect(response).toBe('<p>some html</p>');
		});
	});
});