Socket
Socket
Sign inDemoInstall

vitest-localstorage-mock

Package Overview
Dependencies
516
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

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


Version published
Weekly downloads
22K
decreased by-9.38%
Maintainers
1
Install size
5.97 kB
Created
Weekly downloads
 

Readme

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

Last updated on 08 Mar 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc