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

View file

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