I'm not sure the .button() method in Bootstrap v4 has the options you are trying to use. The Codepen you link to uses Bootstrap v3.
Here is how you could replicate the same behavior with Bootstrap 4.
$(document).ready(function() {
$('.btn').on('click', function() {
var $this = $(this);
var loadingText = ' loading...';
if ($(this).html() !== loadingText) {
$this.data('original-text', $(this).html());
$this.html(loadingText);
}
setTimeout(function() {
$this.html($this.data('original-text'));
}, 2000);
});
})