Skip to content

Commit

Permalink
Add a test for listener order, see #215
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Apr 5, 2023
1 parent 3e7cd95 commit 97d9b18
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions js/TinyEmitterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,22 @@ QUnit.test( 'TinyEmitter onBeforeNotify', assert => {
callForHappinessEmitter.emit();
callForHappinessEmitter.emit();
assert.ok( state.happiness === 5, 'end count' );
} );

QUnit.test( 'TinyEmitter reverse and random', assert => {

assert.ok( true, 'first test' );

const emitter = new TinyEmitter();
const values: string[] = [];
emitter.addListener( () => values.push( 'a' ) );
emitter.addListener( () => values.push( 'b' ) );
emitter.addListener( () => values.push( 'c' ) );
emitter.addListener( () => values.push( 'd' ) );

emitter.emit();
assert.ok( values.join( '' ) === 'abcd', 'normal order' );

// Check these values when running with ?listenerOrder=reverse or ?listenerOrder=random or ?listenerOrder=random(123)
console.log( values.join( '' ) );
} );

0 comments on commit 97d9b18

Please sign in to comment.