npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@suites/unit

v3.0.0

Published

<p align="center"> <img width="200" src="https://raw.githubusercontent.com/suites-dev/suites/master/logo.png" alt="Logo" /> </p>

Downloads

28,475

Readme

Suites is an opinionated, flexible testing meta-framework aim at elevating the software testing experience within backend systems. By integrating a wide array of testing tools into a cohesive framework, Suites simplifies the process of creating reliable tests, thereby ensuring the development of high-quality software.

Codecov Coverage e2e lerna npm downloads

↗️ Visit Documentation    ↗️ API Reference

Automock has been rebranded to Suites 🎉

We are excited to announce that Automock has been rebranded to Suites!

This change reflects our commitment to providing a comprehensive testing solution that caters to a broader range of testing scenarios. The core features and functionality of the framework remain the same, but with a new name and a fresh look.

↗️ Change Log

Core Features

🚀 Zero-Setup Mocking - Automatically generate mock objects, eliminate manual setup, reduce boilerplate code.

🔍 Type-Safe Mocks - Leverage TypeScript's power with mocks that retain the same type as real objects.

📄 Consistent Tests Structure - Test suites will follow a consistent syntax and structure, making them easier to read and maintain.

📈 Optimized Performance - By bypassing the actual DI container, unit tests run significantly faster.

🌐 Community & Support - Join a growing community of developers.

:computer: Quick Example

Suites suggest an alternative approach to writing unit tests for classes instead of using the traditional mocking libraries and dependency injection frameworks.

Take a look at the following example:

Consider the following UserService and Database classes:

export class Database {
  async getUsers(): Promise<User[]> { ... }
}

export class UserService {
  constructor(private database: Database) {}

  async getAllUsers(): Promise<User[]> {
    return this.database.getUsers();
  }
}

Let's create a unit test for this class:

import { TestBed, Mocked } from '@suites/unit';
import { Database, UserService } from './user.service'; 

describe('User Service Unit Spec', () => {
  let userService: UserService; // 🧪 Declare the unit under test
  let database: Mocked<Database>; // 🎭 Declare a mocked dependency

  beforeAll(async () => {
    // 🚀 Create an isolated test env for the unit (under test) + auto generated mock objects
    const { unit, unitRef } = await TestBed.solitary(UserService).compile();

    userService = unit;

    // 🔍 Retreive a dependency (mock) from the unit reference
    database = unitRef.get(Database);
  });

  // ✅ Test test test
  test('should return users from the database', async () => {
    const mockUsers: User[] = [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }];
    database.getUsers.mockResolvedValue(mockUsers);

    const users = await userService.getAllUsers();

    expect(database.getUsers).toHaveBeenCalled();
    expect(users).toEqual(mockUsers);
  });
});

With the use of the TestBed, an instance of the UserService class can be created with mock objects automatically generated for its dependencies. During the test, we have direct access to the automatically generated mock object for the Database dependency (database).

:package: Installation

First, install Suites' core package:

$ npm i -D @suites/unit

Then, to fully integrate Suites into your mocking and dependency injection frameworks, install the corresponding adapters for your project. For example, to use Suites with Jest and NestJS you would run (alongside the core package):

$ npm i -D @suites/doubles.jest @suites/di.nestjs

Suites will automatically detect the installed adapters and configure itself accordingly.

Supported DI Frameworks

| DI Framework | Package Name | |--------------|------------------------| | NestJS | @suites/di.nestjs | | Inversify | @suites/di.inversify | | TSyringe | Soon! |

Supported Mocking Libraries

| DI Framework | Package Name | |--------------|--------------------------| | Jest | @suites/doubles.jest | | Sinon | @suites/doubles.sinon | | Vitest | @suites/doubles.vitest | | Bun | Soon! | | Deno | Soon! |

:scroll: License

Distributed under the Apache (Apache-2.0) License. See LICENSE for more information.