question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@nuxt/test-utils vs @vue/test-utils?

See original GitHub issue

It would be really good to know why using @nuxt/test-utils is more beneficial than using @vue/test-utils in a Nuxt project. Despite the obvious point being this package is made specifically for Nuxt, @vue/test-utils still works perfectly well in Nuxt projects.

Could we get some comparison docs (a table maybe) of what @vue/test-utils can’t do for a Nuxt project, but @nuxt/test-utils can?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

14reactions
mrazauskascommented, Apr 24, 2021

These are two different tools. For the best result use them both.

If we talk about Nuxt apps, @nuxt/test-utils will build an app (or generate a website), launch a server and will provide a browser (all are optional). For example, @nuxt/test-utils might help to check if Nuxt routes, middleware, modules, etc work and if pages are rendered as expected. Public API: get(), url(), createPage(), getNuxt(), etc. Focus on routes, browsing and Nuxt instance, but not Vue components.

We have @vue/test-utils to test Vue components (or Vue app). Public API: mount(), shallowMount(), render(), renderToString(), etc. @vue/test-utils does not build Nuxt apps and knows nothing about Nuxt instance.

(Some details might be missing, but this should help to catch general idea.)

2reactions
mrazauskascommented, Apr 26, 2021

would nuxt/test-utils allow me to test if global errors (unhandled throw errors) that end up in nuxt’s global error handler are caught by the Sentry API module ?

@MentalGear as mentioned before, I don’t know how exactly Sentry works. Here are simply few thoughts which might help you to find a solution.

Your question made me curious to take look at sentry-module’s docs and test suite. A snipped bellow is adapted from examples found there. Docs mention clientIntegrations option. If I get it right, this options sets logErrors: true in dev. Make it log errors in test mode too and use page.on('console') and page.on('pageerror') methods of Playwright’s Page class.

import { setupTest, createPage, url } from '@nuxt/test-utils'

// inside a `describe()` block with `setupTest({ browser: true })`
test('all errors are handled', async () => {
  const page = await createPage() // 1. create Playwright's `page` object

  const messages = []
  page.on('console', (msg) => { // 2. add a listeners
    messages.push(msg.text())
  })

  const errors = []
  page.on('pageerror', (error) => {
    errors.push(error.message)
  })

  await page.goto(url('/some-path')) // 3. navigate

  expect(messages).toEqual(['some expected messages']) // 4. most probably Sentry logs will be here
  expect(errors).toEqual([]) // 5. uncaught errors
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction to Nuxt Test Utils - Reflect.run
Nuxt is a free and open-source JavaScript library built upon Vue that allows you to develop server-rendered web applications. Nuxt Test ...
Read more >
nuxt/test-utils
Easily create tests for your Nuxt projects and modules.
Read more >
Component testing in Nuxt.js with Jest - LogRocket Blog
Set up a game store application with the Nuxt.js framework and test its components. We'll also explore Vuetify and Vuex.
Read more >
Guides | Vue Test Utils
Vue Test Utils (VTU) is a set of utility functions aimed to simplify testing Vue.js components. It provides some methods to mount and...
Read more >
Testing · Get Started with Nuxt
Under the hood, Nuxt test utils uses playwright to carry out browser testing. If this option is set, a browser will be launched...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found