New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vitest-localstorage-mock

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vitest-localstorage-mock

Auto mock all localstorage and sessionstorage APIs for your Vitest tests

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

vitest-localstorage-mock

Auto mock localstorage and sessionstorage in your Vitest scripts for testing.

npm version npm downloads actions status

Install

via pnpm, yarn or npm:

pnpm add -D vitest-localstorage-mock
# or
yarn add -D vitest-localstorage-mock
# or
npm install -D vitest-localstorage-mock

Setup

Module

In your vite.config.(js|ts) under the test configuration section create a setupFiles array and add vitest-localstorage-mock to the array. Also, ensure you have enabled globals We don't need globals any more.

import { defineConfig } from 'vite'

export default defineConfig({
  test: {
    setupFiles: ['vitest-localstorage-mock'],
    mockReset: false,
  }
})

Setup file

Alternatively you can create a new setup file which then requires this module or add the require statement to an existing setup file.

  • __setups__/localstorage.js
import 'vitest-localstorage-mock'

Add that file to your setupFiles array:

import { defineConfig } from 'vite'

export default defineConfig({
  test: {
    setupFiles: ['./__setups__/localstorage.js'],
    mockReset: false,
  }
})

License

MIT © Mitscherlich

Keywords

FAQs

Package last updated on 08 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc