I created a function to check if an element already exist, if not repeat the function until it does:

```
function waitForElementToDisplay(selector) {
    return new Promise(function (resolve, reject) {
        if (document.querySelector(selector) != null) {
            console.log('Element is displayed now');
            resolve();
        } else {
            setTimeout(function () {
                waitForElementToDisplay(selector, 500);
            }, 500);
        }
    })
}

```

I use this function in the `beforeShowPromise` function of Shepherd.js. This function let the package wait with going to the next tour step until the promise is resolved. The `beforeShowPromise` function looks like this:

```
beforeShowPromise: function () {
    return new Promise(async function (resolve) {

        const selector = '.exampleTemplates';

        await waitForElementToDisplay(selector).then(() => {
            console.log('Do something');
        }).catch(err => {
            console.log(err);
        });
    })
},

```

I want to wait until the `waitForElementToDisplay` function is resolved, so the function of Shepherd can be resolved. However, the `.then` nor the `.catch` functions are being called. Can someone explain to me why it isn't working?