Skip to content

Instantly share code, notes, and snippets.

@lucassus
Created September 21, 2011 12:21
Show Gist options
  • Save lucassus/1231897 to your computer and use it in GitHub Desktop.
Save lucassus/1231897 to your computer and use it in GitHub Desktop.
describe('when the code does not exists in the collection', function() {
var $browser;
beforeEach(function() {
$browser = scope.$service('$browser');
});
describe('when validation fails', function() {
beforeEach(function() {
var validationResponse = 'validation fail';
$browser.xhr.expectPOST('/validate', { id: record.id, code: 'code-666' }).
respond(200, validationResponse);
validator.validate('code-666', validationDone);
$browser.xhr.flush();
});
it('should set validation message', function() {
expect(validationDone).toHaveBeenCalledWith('exists in database');
});
});
describe('when validation pass', function() {
beforeEach(function() {
var validationResponse = null;
$browser.xhr.expectPOST('/validate', { id: record.id, code: 'code-666' }).
respond(200, validationResponse);
validator.validate('code-666', validationDone);
$browser.xhr.flush();
});
it('should set validation message via hxr', function() {
expect(validationDone).toHaveBeenCalledWith(false);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment