1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

add test for callback execution order

This commit is contained in:
kbparagua 2016-03-24 22:06:33 +08:00
parent ce3b147173
commit 9a8668e496

View file

@ -3,27 +3,29 @@ describe('Paloma.BeforeCallbackPerformer', function(){
var Controller = Paloma.controller('MyController', {
before: [
'all -> doThat',
'all -> initialize doThat',
'singleCallback unknown -> doSomething',
'multiCallback -> doSomething doAnotherThing'
],
didThat: false,
didSomething: false,
didAnotherThing: false,
initialize: function(){
this.didWhat = [];
},
did: function(what){ return this.didWhat.indexOf(what) >= 0; },
noCallback: function(){ console.log('I have no callback.'); },
singleCallback: function(){ console.log('Single callback.'); },
multiCallback: function(){ console.log('Multiple callbacks.')},
doThat: function(){ this.didThat = true; },
doSomething: function(){ this.didSomething = true; },
doAnotherThing: function(){ this.didAnotherThing = true; }
doThat: function(){ this.didWhat.push('that'); },
doSomething: function(){ this.didWhat.push('something'); },
doAnotherThing: function(){ this.didWhat.push('anotherThing') }
});
function itPerformsCallbackForAll(controller){
it('performs callback for all', function(){
expect(controller.didThat).toBeTruthy();
expect( controller.did('that') ).toBeTruthy();
});
};
@ -34,7 +36,7 @@ describe('Paloma.BeforeCallbackPerformer', function(){
performer.perform('noCallback');
it('will not perform any callback', function(){
expect(controller.didSomething).toBeFalsy();
expect( controller.did('something') ).toBeFalsy();
});
itPerformsCallbackForAll(controller);
@ -47,7 +49,7 @@ describe('Paloma.BeforeCallbackPerformer', function(){
performer.perform('singleCallback');
it('will perform the matched callback', function(){
expect(controller.didSomething).toBeTruthy();
expect( controller.did('something') ).toBeTruthy();
});
itPerformsCallbackForAll(controller);
@ -60,10 +62,16 @@ describe('Paloma.BeforeCallbackPerformer', function(){
performer.perform('multiCallback');
it('will perform all the matched callbacks', function(){
expect(controller.didSomething && controller.didAnotherThing).
expect( controller.did('something') && controller.did('anotherThing') ).
toBeTruthy();
});
it('will perform the callbacks in order of definition', function(){
expect(controller.didWhat).toEqual([
'that', 'something', 'anotherThing'
]);
});
itPerformsCallbackForAll(controller);
});