1
0
Fork 0

[DEV-7060] Set document in constructor of ElementStyler

Mark Goldsmith 2020-02-19 08:51:03 -05:00
parent e9ded067b1
commit 1e76291ada
2 changed files with 19 additions and 8 deletions

View File

@ -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 )

View File

@ -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 );