Socket
Socket
Sign inDemoInstall

@testing-library/svelte

Package Overview
Dependencies
Maintainers
0
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testing-library/svelte

Simple and complete Svelte testing utilities that encourage good testing practices.


Version published
Weekly downloads
118K
decreased by-0.9%
Maintainers
0
Weekly downloads
 
Created

What is @testing-library/svelte?

@testing-library/svelte is a library for testing Svelte components. It provides utilities to render Svelte components, query elements, and simulate user interactions, making it easier to write tests that resemble how users interact with your application.

What are @testing-library/svelte's main functionalities?

Rendering Components

This feature allows you to render Svelte components in a test environment. The `render` function returns utility functions to query the rendered component.

const { render } = require('@testing-library/svelte');
const MyComponent = require('./MyComponent.svelte');

const { getByText } = render(MyComponent);
expect(getByText('Hello World')).toBeInTheDocument();

Querying Elements

This feature provides various query functions like `getByText` and `getByRole` to find elements in the rendered component.

const { render } = require('@testing-library/svelte');
const MyComponent = require('./MyComponent.svelte');

const { getByText, getByRole } = render(MyComponent);
expect(getByText('Submit')).toBeInTheDocument();
expect(getByRole('button')).toBeInTheDocument();

Simulating User Interactions

This feature allows you to simulate user interactions like clicks, typing, etc., using the `fireEvent` utility.

const { render, fireEvent } = require('@testing-library/svelte');
const MyComponent = require('./MyComponent.svelte');

const { getByText } = render(MyComponent);
const button = getByText('Click me');
await fireEvent.click(button);
expect(getByText('Clicked')).toBeInTheDocument();

Other packages similar to @testing-library/svelte

Keywords

FAQs

Package last updated on 20 Jun 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