Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Using a real router with Composition API example is missing flushPromises #1894

Closed
evandroguedes opened this issue Dec 5, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@evandroguedes
Copy link
Contributor

Describe the bug
In the docs there is a code example for Using a real router with Composition API. Here is the code example in it's current state:

import { mount, flushPromises } from '@vue/test-utils'
import { createRouter, createWebHistory } from 'vue-router'
import { routes } from "@/router"

let router;

beforeEach(async () => {
  router = createRouter({
    history: createWebHistory(),
    routes: routes,
  })

  router.push('/')
  await router.isReady()
});

test('allows authenticated user to edit a post', async () => {
  const wrapper = mount(Component, {
    props: {
      isAuthenticated: true
    },
    global: {
      plugins: [router],
    }
  })

  const push = jest.spyOn(router, 'push')
  await wrapper.find('button').trigger('click')

  expect(push).toHaveBeenCalledTimes(1)
  expect(push).toHaveBeenCalledWith('/posts/1/edit')
})

flushPromises is imported but is not used anywhere.

How should that be handled? Should the flushPromises be called after the button trigger event? I'd be happy to put up a PR for it!

@evandroguedes evandroguedes added the bug Something isn't working label Dec 5, 2022
@cexbrayat
Copy link
Member

Hi @evandroguedes

I think flushPromises is not needed here, and can simply be removed.

A PR fixing this would be great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants