Test: Migrate changeListener.test.js to node-qunit

Change-Id: Ib6d5156d2f1bc56c113866ed0510966586d9ca07
This commit is contained in:
joakin 2017-02-15 16:22:50 +01:00
parent f3839189dc
commit d2d7ab10fa
2 changed files with 55 additions and 56 deletions

View file

@ -0,0 +1,55 @@
var registerChangeListener = require( '../../src/changeListener' ),
stubStore;
stubStore = ( function () {
var state;
return {
getState: function () {
return state;
},
setState: function ( 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'
}
) );
} );

View file

@ -1,56 +0,0 @@
( function ( mw ) {
var stubStore = ( function () {
var state;
return {
getState: function () {
return state;
},
setState: function ( 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;
};
mw.popups.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'
}
) );
} );
}( mediaWiki ) );