Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Change queue.handler to send null if the queue has no errors #74

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
2 changes: 1 addition & 1 deletion src/common/libs/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Queue.prototype = {

handler: function(fn, context) {
this._runOrStore(function() {
fn.apply(context, this.getErrors());
fn.apply(context, this.hasErrors()? this.getErrors() : [null]);
});
return this;
},
Expand Down
4 changes: 2 additions & 2 deletions test/NormalizedCollection/Record.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ describe('Record', function() {
expect(spy).not.toHaveBeenCalled();
}
});
expect(spy).toHaveBeenCalledWith();
expect(spy).toHaveBeenCalledWith(null);
});

it('triggers callback with correct context', function() {
Expand All @@ -450,7 +450,7 @@ describe('Record', function() {
_.each(refs, function(ref) {
try { ref.flush(); } catch(e) {}
});
expect(spy).toHaveBeenCalledWith();
expect(spy).toHaveBeenCalledWith(null);
});

it('returns an error if any path returns an error', function() {
Expand Down
41 changes: 41 additions & 0 deletions test/common/queue.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';
var fbutil = require('../../src/common');

describe('common/Queue.js', function() {

describe('#handler', function() {
it('should call handler callback with null if the queue has no errors', function() {
var q = fbutil.queue();
var handler = q.getHandler();

var callback = jasmine.createSpy();

q.handler(callback);

expect(q.hasErrors()).toBe(0);

handler();

expect(q.hasErrors()).toBe(0);
expect(callback).toHaveBeenCalledWith(null);
});

it('should call handler callback with the first error if the queue has errors', function() {
var q = fbutil.queue();
var handler = q.getHandler();

var callback = jasmine.createSpy();
var error = new Error();

q.handler(callback);

expect(q.hasErrors()).toBe(0);

handler(error);

expect(q.hasErrors()).toBe(1);
expect(callback).toHaveBeenCalledWith(error);
});
});

});