Fix a JS race in a spec Closes #56860 See merge request gitlab-org/gitlab-ce!24684 (cherry picked from commit b5e10cd3)