{"library":"spy4js","title":"Spy4js Testing Spy Framework","type":"library","description":"Spy4js is a standalone JavaScript and TypeScript testing spy framework designed for integration with test runners like Vitest and Jest. It provides a robust API for creating and managing spies, focusing on test readability, detailed error messages, and efficient serialization of call arguments. The package aims to offer an intuitive alternative or supplement to the built-in spying capabilities of popular test frameworks. The current stable version is 5.0.0, released in September 2025. While release cadence can be irregular, significant updates (like the TypeScript migration in v3.0.0) introduce notable breaking changes. Key differentiators include an API optimized for readability, enhanced error reporting with detailed comparisons, and features like customizable behavior and module mocking capabilities for both CommonJS and ES Modules.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install spy4js"],"cli":null},"imports":["import { Spy } from 'spy4js';","import { Spy } from 'spy4js'; const spy = Spy.on(someObject, 'methodName');","import { Spy } from 'spy4js'; const moduleMocks = Spy.mock(await import('./my-module'), 'useMe');"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/fdc-viktor-luft/spy4js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/spy4js","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import { Spy } from 'spy4js';\n\n// Initialize a basic spy\nconst mySpy = Spy('myFunctionSpy');\n\n// Simulate calling the spy\nmySpy(1, 2, 'hello');\nmySpy({ data: 'test' });\n\n// Assertions\nif (!mySpy.wasCalled()) {\n  throw new Error('mySpy was not called!');\n}\n\nif (!mySpy.wasCalledWith(1, 2, 'hello')) {\n  throw new Error('mySpy was not called with expected arguments!');\n}\n\nif (mySpy.getCallCount() !== 2) {\n  throw new Error(`Expected 2 calls, got ${mySpy.getCallCount()}`);\n}\n\nconsole.log('Spy calls:', mySpy.getAllCallArguments());\n\n// Mock an existing object's method\nconst service = { \n  getData: (id: string) => `Data for ${id}`,\n  process: () => 'done'\n};\nconst getDataSpy = Spy.on(service, 'getData').returns('Mocked Data');\n\nconsole.log(service.getData('123')); // Outputs: Mocked Data\nif (!getDataSpy.wasCalledWith('123')) {\n  throw new Error('getDataSpy was not called as expected!');\n}\n\nconsole.log('All good with spy4js!');","lang":"typescript","description":"Demonstrates initializing a spy, simulating calls, and performing basic assertions like checking call count and arguments, and mocking an existing object's method.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}