Merge "[qunit] Use more stubs for test setup"

This commit is contained in:
jenkins-bot 2024-12-20 11:23:16 +00:00 committed by Gerrit Code Review
commit 3b83aea30d
2 changed files with 13 additions and 21 deletions

View file

@ -9,13 +9,12 @@ function createStubTitle( fragment = null ) {
( mw.loader.getModuleNames().indexOf( 'ext.popups.main' ) !== -1 ? ( mw.loader.getModuleNames().indexOf( 'ext.popups.main' ) !== -1 ?
QUnit.module : QUnit.module :
QUnit.module.skip )( 'ext.cite.referencePreviews#createReferenceGateway', { QUnit.module.skip )( 'ext.cite.referencePreviews#createReferenceGateway', {
beforeEach() { beforeEach: function () {
// FIXME: Is this needed? this.sandbox.stub( mw, 'msg', ( key ) => `<${ key }>` );
// global.CSS = { this.sandbox.stub( mw, 'message', ( key ) => ( {
// escape: ( str ) => $.escapeSelector( str ) exists: () => !key.endsWith( 'generic' ),
// }; text: () => `<${ key }>`
mw.msg = ( key ) => `<${ key }>`; } ) );
mw.message = ( key ) => ( { exists: () => !key.endsWith( 'generic' ), text: () => `<${ key }>` } );
this.$sourceElement = $( '<a>' ).appendTo( this.$sourceElement = $( '<a>' ).appendTo(
$( '<sup>' ).attr( 'id', 'cite_ref-1' ).appendTo( document.body ) $( '<sup>' ).attr( 'id', 'cite_ref-1' ).appendTo( document.body )
@ -49,8 +48,6 @@ function createStubTitle( fragment = null ) {
).appendTo( document.body ); ).appendTo( document.body );
}, },
afterEach() { afterEach() {
mw.msg = null;
mw.message = null;
this.$sourceElement.parent().remove(); this.$sourceElement.parent().remove();
this.$references.remove(); this.$references.remove();
} }

View file

@ -7,18 +7,13 @@ const previewTypes = { TYPE_REFERENCE: 'reference' };
before() { before() {
createReferencePreview = require( 'ext.cite.referencePreviews' ).private.createReferencePreview; createReferencePreview = require( 'ext.cite.referencePreviews' ).private.createReferencePreview;
}, },
beforeEach() { beforeEach: function () {
mw.msg = ( key ) => `<${ key }>`; this.sandbox.stub( mw, 'msg', ( key ) => `<${ key }>` );
mw.message = ( key ) => ( { exists: () => !key.endsWith( 'generic' ), text: () => `<${ key }>` } ); this.sandbox.stub( mw, 'message', ( key ) => ( {
exists: () => !key.endsWith( 'generic' ),
mw.html = { text: () => `<${ key }>`
escape: ( str ) => str && str.replace( /'/g, '&apos;' ).replace( /</g, '&lt;' ) } ) );
}; this.sandbox.stub( mw.html, 'escape', ( str ) => str && str.replace( /'/g, '&apos;' ).replace( /</g, '&lt;' ) );
},
afterEach() {
mw.msg = null;
mw.message = null;
mw.html = null;
} }
} ); } );