6
\$\begingroup\$

https://codereview.stackexchange.com/questions/87366/unit-testing-ui-related-modules

A module + test could look something like this:

   var uiModule = (function($){

   function init(){
        getData().done(function(data){
            addResultToUi();
            bindEvents();
        });
    }

   function getData(){
        return $.ajax({ url: 'something' });
    }

   function addResultToUi(data){
        $('.dummy').append('<p>' + data.text + '</p>')
    }

   function bindEvents(){
        $('.dummy').on('click', function(){
            $(this).text('blah');
        });
    }

   return {
        init: init 
    };

})(jQuery);
function setup(){
    uiModule.init();
}

function tearDown(){
    uiModule = null;
}

test('data text added to dummy element', function(assert){
     var result = $('.dummy > p').text();
     assert.ok(result.length > 0);
});

test('click on dummy sets text to blah', function(assert){
     var $dummy = $('.dummy');
     $dummy.trigger('click');
     assert.equal('foo', $dummy.text());
});

That looks like example code to me.

I think it would be best if the bounty was refunded and the question closed.

\$\endgroup\$
4
\$\begingroup\$

I agree with you. See this relevant information in the question :

A module + test could look something like this

This is a clear indicator that it is not real code but example code. I think we should refund and close the question, if the user don't want to provide the real code and real tests. I think it could be on-topic if would be about real code.

\$\endgroup\$
  • 2
    \$\begingroup\$ Agreed. I've refunded the bounty and put the question on hold. \$\endgroup\$ – 200_success Apr 29 '15 at 16:11
  • \$\begingroup\$ Should we custom-flag such bounty questions or treat them as 'normal' questions? \$\endgroup\$ – Mast Apr 30 '15 at 13:35
  • \$\begingroup\$ You can't close a question when there is a bounty on it. Only a mod can refund the bounty and close the question. So flagging is the way, not you sure you can cast close vote. \$\endgroup\$ – Marc-Andre Apr 30 '15 at 13:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .