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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@remotex-labs/xjet-expect

v2.1.4

Published

xJet-Expect: Powerful Assertions for Seamless xJet Testing

Downloads

74

Readme

xJet Matcher Utilities

npm version npm version License: MPL 2.0 Node.js CI Discord Ask DeepWiki

A TypeScript-based matcher library for testing mocks and verifying function calls, thrown errors, and returned values.
Inspired by Jest-style assertions with xJet support for extended mock / spy in esm.

Installation

Install via npm:

npm install --save-dev @remotex-labs/xjet-expect

Or using yarn:

yarn add @remotex-labs/xjet-expect

Features

  • TypeScript First: Full TypeScript support with comprehensive type definitions
  • Modern ESM Support: Works seamlessly with ES modules
  • Detailed Error Messages: Helpful, colorized error output for failed assertions
  • Asymmetric Matchers: Flexible partial matching for complex objects
  • Mock Tracking: Comprehensive mock function call tracking and assertions
  • Promise Testing: First-class support for async/await and Promise testing

Quick Start

import { xExpect, test } from '@remotex-labs/xjet-expect';

test('basic assertions', () => {
  // Equality
  xExpect(2 + 2).toBe(4);
  xExpect({ name: 'test' }).toEqual({ name: 'test' });
  
  // Truthiness
  xExpect(true).toBeTruthy();
  xExpect(null).toBeFalsy();
  
  // Numbers
  xExpect(10).toBeGreaterThan(5);
  xExpect(5).toBeLessThanOrEqual(5);
  
  // Strings
  xExpect('hello world').toContain('world');
  xExpect('test string').toMatch(/test/);
  
  // Objects
  xExpect({ user: { name: 'John' } }).toHaveProperty('user.name');
});

Mock Functions

import { xExpect, test, jest } from '@remotex-labs/xjet-expect';

test('mock function calls', () => {
  const mockFn = xJet.fn();
  
  mockFn('first call');
  mockFn('second call');
  
  // Verify calls
  xExpect(mockFn).toHaveBeenCalled();
  xExpect(mockFn).toHaveBeenCalledTimes(2);
  xExpect(mockFn).toHaveBeenCalledWith('first call');
  xExpect(mockFn).toHaveBeenLastCalledWith('second call');
  xExpect(mockFn).toHaveBeenNthCalledWith(1, 'first call');
});

test('mock return values', () => {
  const mockFn = xJet.fn()
    .mockReturnValueOnce('first')
    .mockReturnValueOnce('second');
  
  xExpect(mockFn()).toBe('first');
  xExpect(mockFn()).toBe('second');
  
  xExpect(mockFn).toHaveReturned();
  xExpect(mockFn).toHaveReturnedTimes(2);
  xExpect(mockFn).toHaveLastReturnedWith('second');
  xExpect(mockFn).toHaveNthReturnedWith(1, 'first');
});

Async Testing

import { xExpect, test } from '@remotex-labs/xjet-expect';

test('async functions', async () => {
  // Promise resolution
  await xExpect(Promise.resolve('success')).resolves.toBe('success');
  await xExpect(Promise.resolve({ id: 123 })).resolves.toHaveProperty('id');
  
  // Promise rejection
  await xExpect(Promise.reject(new Error('failed'))).rejects.toThrow('failed');
  
  // Async functions
  const fetchData = async () => ({ id: 123, name: 'test' });
  await xExpect(fetchData()).resolves.toEqual(
    xExpect.objectContaining({ id: xExpect.any(Number) })
  );
});

Asymmetric Matchers

import { xExpect, test } from '@remotex-labs/xjet-expect';

test('flexible assertions with asymmetric matchers', () => {
  const user = {
    id: 123,
    name: 'John Doe',
    email: '[email protected]',
    createdAt: new Date(),
    roles: ['user', 'admin']
  };
  
  xExpect(user).toEqual(xExpect.objectContaining({
    id: xExpect.any(Number),
    name: xExpect.stringContaining('John'),
    email: xExpect.stringMatching(/^.+@example\.com$/),
    createdAt: xExpect.any(Date),
    roles: xExpect.arrayContaining(['admin'])
  }));
});

Custom Matchers

import { xExpect } from '@remotex-labs/xjet-expect';

// Define a custom matcher
xExpect.extend({
  toBeEvenNumber(received) {
    const pass = typeof received === 'number' && received % 2 === 0;
    
    return {
      pass,
      message: () => `Expected ${received} ${pass ? 'not ' : ''}to be an even number`
    };
  }
});

// Use custom matcher
test('custom matchers', () => {
  xExpect(4).toBeEvenNumber();
  xExpect(3).not.toBeEvenNumber();
});

Documentation

For complete API documentation, examples, and guides, visit: xJet-expect Documentation

Compatibility

  • Node.js 20+
  • All modern browsers (via bundlers)
  • TypeScript 4.5+
  • Compatible with Jest assertions for easy migration

Contributing

Contributions are welcome! Please see our Contributing Guide for details.

License

This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.

Acknowledgments

  • Inspired by Jest's expect API
  • Built with TypeScript
  • Powered by the xJet ecosystem