From d2d7ab10faea07db21b0c0799dd55221d62103b5 Mon Sep 17 00:00:00 2001 From: joakin Date: Wed, 15 Feb 2017 16:22:50 +0100 Subject: [PATCH] Test: Migrate changeListener.test.js to node-qunit Change-Id: Ib6d5156d2f1bc56c113866ed0510966586d9ca07 --- tests/node-qunit/changeListener.test.js | 55 ++++++++++++++++++ tests/qunit/ext.popups/changeListener.test.js | 56 ------------------- 2 files changed, 55 insertions(+), 56 deletions(-) create mode 100644 tests/node-qunit/changeListener.test.js delete mode 100644 tests/qunit/ext.popups/changeListener.test.js diff --git a/tests/node-qunit/changeListener.test.js b/tests/node-qunit/changeListener.test.js new file mode 100644 index 000000000..15c1a16d9 --- /dev/null +++ b/tests/node-qunit/changeListener.test.js @@ -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' + } + ) ); +} ); diff --git a/tests/qunit/ext.popups/changeListener.test.js b/tests/qunit/ext.popups/changeListener.test.js deleted file mode 100644 index 6ffb3dedf..000000000 --- a/tests/qunit/ext.popups/changeListener.test.js +++ /dev/null @@ -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 ) );