\vspace not working as expected

I have a code block using minted and mdframed and a caption afterwards.

\begin{mdframed}
\begin{minted}[tabsize=4]{c++}
some code
\end{minted}
\end{mdframed}
\begingroup\captionof{listing}{some caption\label{lst:label}}\endgroup


The caption however is too far away from the code. I tried adding negative vertical space right after the frame, however it doesn't work correctly. Up to \vspace{-4em} nothing happens, but with \vspace{-5em}, the caption is moved right into the code block.

How can I move the caption that it is positioned right after the code block?

When I use \unskip after the frame, the caption will be positioned right after it. \vspace also works now, but is not needed anymore, at least for my case.