mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-24 15:44:09 +00:00
e6081106f1
Why: Because they are the approved standard by TC39 and Ecma for JavaScript modules. Changes: * Wrap mw-node-qunit in run.js to register babel to transpile modules for node v6 * Change all sources in src/ to use ES modules * Change constants.js to be able to run without jQuery.bracketedDevicePixelRatio given ES modules are hoisted to the top by spec so we can't patch globals before importing it * Change all tests in tests/node-qunit/ to use ES modules * Drop usage of mock-require given ES modules are easy to stub with sinon Additional changes: * Rename tests/node-qunit/renderer.js to renderer.test.js to follow the convention of all the other files * Make npm run test:node run only .test.js test files so that it doesn't run the stubs.js or run.js file. Bug: T171951 Change-Id: I17a0b76041d5e2fd18e2d54950d9d7c0db99a941
55 lines
997 B
JavaScript
55 lines
997 B
JavaScript
import registerChangeListener from '../../src/changeListener';
|
|
|
|
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;
|
|
};
|
|
|
|
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'
|
|
}
|
|
) );
|
|
} );
|