{"record":{"id":"842ae40b7b5388d2","repo":"vuejs/core","slug":"test-case-threw-unexpected-warnings-n-nonasse","errorCode":null,"errorMessage":"test case threw unexpected warnings:\\n - ${nonAssertedWarnings.join('\\n - ')}","messagePattern":"test case threw unexpected warnings:\\\\n - (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/setup-vitest.ts","lineNumber":101,"sourceCode":"\nbeforeEach(() => {\n  asserted.clear()\n  warn = vi.spyOn(console, 'warn')\n  warn.mockImplementation(() => {})\n})\n\nafterEach(() => {\n  const assertedArray = Array.from(asserted)\n  const nonAssertedWarnings = warn.mock.calls\n    .map(args => args[0])\n    .filter(received => {\n      return !assertedArray.some(assertedMsg => {\n        return received.includes(assertedMsg)\n      })\n    })\n  warn.mockRestore()\n  if (nonAssertedWarnings.length) {\n    throw new Error(\n      `test case threw unexpected warnings:\\n - ${nonAssertedWarnings.join(\n        '\\n - ',\n      )}`,\n    )\n  }\n})\n","sourceCodeStart":83,"sourceCodeEnd":108,"githubUrl":"https://github.com/vuejs/core/blob/a2b40db9a83b36ed9da3a16403cf8f040262d73f/scripts/setup-vitest.ts#L83-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Assert the warning in the test using Vue's test-utils `expect(...).toHaveBeenWarned` / `expectWarning` helper so the warning is consumed.","Fix the underlying code so it no longer emits the unexpected warning.","If the warning is intentional but irrelevant to the test, suppress/assert it explicitly rather than ignoring it.","Re-run just the failing test with the vitest reporter to see the exact unasserted warning text, then address it."],"exampleFix":"// before — test triggers a warning but doesn't assert\nexpect(root.html()).toContain('hi')\n\n// after\nexpect(root.html()).toContain('hi')\nexpect(`Invalid prop`).toHaveBeenWarned()","handlingStrategy":"validation","validationCode":"// In Vue's own test suite: assert every warning your test triggers.\n// Use the test-utils helper to register expected warnings before they fire.\nexpect(`Invalid prop type`).toHaveBeenWarned()\n// or assert the call count\nexpect(`Invalid prop type`).toHaveBeenWarnedLast()\n// Clear between tests if needed\nafterEach(() => clearWarn())","typeGuard":"function warningWasAsserted(received: string, asserted: string[]): boolean {\n  return asserted.some(a => received.includes(a))\n}","tryCatchPattern":null,"preventionTips":["Whenever a test triggers a dev warning, assert it with the test-utils warn helper.","After refactors that add warnings, update the test's asserted-warning list.","Fix the underlying code rather than letting stray warnings slip through."],"tags":["vue","testing","vitest","warnings","test-infrastructure"],"backgroundTag":null,"analyzedSha":"a2b40db9a83b36ed9da3a16403cf8f040262d73f","analyzedAt":"2026-08-12T14:21:14.989Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}