vuejs/core · error · Error

test case threw unexpected warnings:\n - ${nonAssertedWarnin

Error message

test case threw unexpected warnings:\n - ${nonAssertedWarnings.join('\n - ')}

What it means

Thrown by the vitest setup (scripts/setup-vitest.ts) in an afterEach hook. Vue's test suite mocks the dev-time `warn` function and tracks which warnings each test asserted with `expect(...).to.have.been.warned`. Any warning emitted but not asserted is treated as a test failure. setup-vitest.ts:101 lists the unasserted warnings in the error message.

Source

Thrown at scripts/setup-vitest.ts:101

beforeEach(() => {
  asserted.clear()
  warn = vi.spyOn(console, 'warn')
  warn.mockImplementation(() => {})
})

afterEach(() => {
  const assertedArray = Array.from(asserted)
  const nonAssertedWarnings = warn.mock.calls
    .map(args => args[0])
    .filter(received => {
      return !assertedArray.some(assertedMsg => {
        return received.includes(assertedMsg)
      })
    })
  warn.mockRestore()
  if (nonAssertedWarnings.length) {
    throw new Error(
      `test case threw unexpected warnings:\n - ${nonAssertedWarnings.join(
        '\n - ',
      )}`,
    )
  }
})

View on GitHub (pinned to a2b40db9a8)

Solutions

  1. Assert the warning in the test using Vue's test-utils `expect(...).toHaveBeenWarned` / `expectWarning` helper so the warning is consumed.
  2. Fix the underlying code so it no longer emits the unexpected warning.
  3. If the warning is intentional but irrelevant to the test, suppress/assert it explicitly rather than ignoring it.
  4. Re-run just the failing test with the vitest reporter to see the exact unasserted warning text, then address it.

Example fix

// before — test triggers a warning but doesn't assert
expect(root.html()).toContain('hi')

// after
expect(root.html()).toContain('hi')
expect(`Invalid prop`).toHaveBeenWarned()
Defensive patterns

Strategy: validation

Validate before calling

// In Vue's own test suite: assert every warning your test triggers.
// Use the test-utils helper to register expected warnings before they fire.
expect(`Invalid prop type`).toHaveBeenWarned()
// or assert the call count
expect(`Invalid prop type`).toHaveBeenWarnedLast()
// Clear between tests if needed
afterEach(() => clearWarn())

Type guard

function warningWasAsserted(received: string, asserted: string[]): boolean {
  return asserted.some(a => received.includes(a))
}

Prevention

When it happens

Trigger: A test triggers a Vue dev warning (e.g. a prop validation failure, a deprecation, a runtime warning) but does not assert it. Adding code that newly emits a warning to an existing test without updating its assertions.

Common situations: Refactoring that introduces a new warning in a code path exercised by tests; updating Vue and gaining a new dev warning; a test that previously relied on behavior now deprecated.

Related errors


AI-assisted analysis of vuejs/core@a2b40db9a8 (2026-08-12). Data as JSON: /api/errors/842ae40b7b5388d2. Report an issue: GitHub.