Skip to content

Commit

Permalink
add Node-like TinyProperty unit test, phetsims/scenery#1131
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Feb 17, 2021
1 parent 0791b26 commit 2089859
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion js/TinyEmitterTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,4 @@ QUnit.test( 'TinyEmitter onBeforeNotify', assert => {
callForHappinessEmitter.emit();
callForHappinessEmitter.emit();
assert.ok( state.happiness === 5, 'end count' );

} );
29 changes: 29 additions & 0 deletions js/TinyPropertyTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,33 @@ QUnit.test( 'TinyProperty Basics', assert => {
} );

assert.ok( true, 'one test' );
} );

QUnit.test( 'TinyProperty onBeforeNotify', assert => {

class MyObservedObject {
constructor() {
this.hasFun = false;
this.hadFun = false;
this.hasFunProperty = new TinyProperty( false, ( newValue, oldValue ) => {
this.hasFun = newValue;
this.hadFun = oldValue;
} );
}
}

const x = new MyObservedObject();

x.hasFunProperty.lazyLink( ( newValue, oldValue ) => {
assert.ok( x.hadFun === oldValue, 'old value should match' );
assert.ok( x.hasFun === newValue, 'new value should match' );
} );


x.hasFunProperty.value = true;
x.hasFunProperty.value = false;
x.hasFunProperty.value = true;
x.hasFunProperty.value = 42;
x.hasFunProperty.value = 'duh';
x.hasFunProperty.value = 'always';
} );

0 comments on commit 2089859

Please sign in to comment.