[DEV-7060] Set document in constructor of ElementStyler
parent
e9ded067b1
commit
1e76291ada
|
@ -88,6 +88,12 @@ module.exports = Class( 'ElementStyler',
|
|||
*/
|
||||
'private _jquery': null,
|
||||
|
||||
/**
|
||||
* HTML Document
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
'private _document': null,
|
||||
|
||||
|
||||
_answerStyles: {
|
||||
'deductible': function( value, _, default_val )
|
||||
|
@ -193,6 +199,7 @@ module.exports = Class( 'ElementStyler',
|
|||
{
|
||||
this._$context = jquery;
|
||||
this._jquery = jquery;
|
||||
this._document = jquery( 'body' ).context;
|
||||
},
|
||||
|
||||
|
||||
|
@ -855,10 +862,10 @@ module.exports = Class( 'ElementStyler',
|
|||
if ( hasindex )
|
||||
{
|
||||
var id = this._getElementId( name, index );
|
||||
|
||||
|
||||
if ( id )
|
||||
{
|
||||
element = document.getElementById( id );
|
||||
element = this._document.getElementById( id );
|
||||
|
||||
// let's hope for the best
|
||||
if ( element !== null )
|
||||
|
|
|
@ -115,10 +115,15 @@ describe( 'ui.ElementStyler', () =>
|
|||
{
|
||||
it( "determines the correct element id for " + name, () =>
|
||||
{
|
||||
// Stub all objects
|
||||
$ = sinon.stub();
|
||||
jQuery = sinon.stub();
|
||||
document = sinon.stub();
|
||||
// Stub document and jQuery calls
|
||||
$ = sinon.stub();
|
||||
jQuery = sinon.stub();
|
||||
|
||||
const document = {
|
||||
getElementById: sinon.stub()
|
||||
};
|
||||
|
||||
jQuery.withArgs( 'body' ).returns( { context: document } );
|
||||
|
||||
const sut = Sut( jQuery );
|
||||
|
||||
|
@ -136,12 +141,11 @@ describe( 'ui.ElementStyler', () =>
|
|||
html: html,
|
||||
};
|
||||
|
||||
document.getElementById = sinon.stub();
|
||||
document.getElementById.returns( node );
|
||||
|
||||
sut.getWidgetByName( name, index, null, context );
|
||||
|
||||
const actual_id = document.getElementById.getCall(0).args[0];
|
||||
const actual_id = document.getElementById.getCall( 0 ).args[ 0 ];
|
||||
|
||||
expect( actual_id )
|
||||
.to.equal( expected_id );
|
||||
|
|
Loading…
Reference in New Issue