mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-15 03:34:03 +00:00
a67466acc0
Replace easily identifiable object functions with method syntax: find \ -not \( \( -name node_modules -o -name .git -o -name vendor -o -name doc -o -name resources \) -prune \) \ -iname \*.js| xargs -rd\\n sed -ri 's%:\s*function\s*(\([^)]*\))%\1%g' Bug: T165036 Change-Id: I90693ee99a6a36dff820dd5ae6f6000429763058
55 lines
975 B
JavaScript
55 lines
975 B
JavaScript
import registerChangeListener from '../../src/changeListener';
|
|
|
|
var stubStore = ( function () {
|
|
var state;
|
|
|
|
return {
|
|
getState() {
|
|
return state;
|
|
},
|
|
setState( value ) {
|
|
state = value;
|
|
}
|
|
};
|
|
}() );
|
|
|
|
QUnit.module( 'ext.popups/changeListener' );
|
|
|
|
QUnit.test( 'it should only call the callback when the state has changed', function ( assert ) {
|
|
var spy = this.sandbox.spy(),
|
|
boundChangeListener;
|
|
|
|
stubStore.subscribe = function ( changeListener ) {
|
|
boundChangeListener = changeListener;
|
|
};
|
|
|
|
registerChangeListener( stubStore, spy );
|
|
|
|
assert.expect( 4 );
|
|
|
|
stubStore.setState( {} );
|
|
|
|
boundChangeListener();
|
|
boundChangeListener();
|
|
|
|
assert.strictEqual( spy.callCount, 1 );
|
|
assert.ok( spy.calledWith(
|
|
undefined, // The initial internal state of the change listener.
|
|
{}
|
|
) );
|
|
|
|
stubStore.setState( {
|
|
foo: 'bar'
|
|
} );
|
|
|
|
boundChangeListener();
|
|
|
|
assert.strictEqual( spy.callCount, 2 );
|
|
assert.ok( spy.calledWith(
|
|
{},
|
|
{
|
|
foo: 'bar'
|
|
}
|
|
) );
|
|
} );
|