{"id":21870121,"url":"https://github.com/anmiles/jest-extensions","last_synced_at":"2026-04-10T15:08:22.561Z","repository":{"id":220022095,"uuid":"750528667","full_name":"anmiles/jest-extensions","owner":"anmiles","description":"Extension functions and utils for jest","archived":false,"fork":false,"pushed_at":"2025-07-24T07:17:36.000Z","size":2875,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-24T08:52:11.225Z","etag":null,"topics":["extend","javascript","jest","library","matcher","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anmiles.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-01-30T20:09:22.000Z","updated_at":"2025-07-24T07:17:38.000Z","dependencies_parsed_at":"2025-06-12T08:27:49.518Z","dependency_job_id":"95583292-2e0c-4c37-8da5-0ab7619c0967","html_url":"https://github.com/anmiles/jest-extensions","commit_stats":null,"previous_names":["anmiles/jest-extensions"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/anmiles/jest-extensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anmiles%2Fjest-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anmiles%2Fjest-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anmiles%2Fjest-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anmiles%2Fjest-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anmiles","download_url":"https://codeload.github.com/anmiles/jest-extensions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anmiles%2Fjest-extensions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267905183,"owners_count":24163862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extend","javascript","jest","library","matcher","nodejs","typescript"],"created_at":"2024-11-28T06:10:10.612Z","updated_at":"2025-12-30T21:55:00.360Z","avatar_url":"https://github.com/anmiles.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @anmiles/jest-extensions\n\nExtension functions and utils for jest\n\n----\n\n## Installation\n\n`npm install --save-dev @anmiles/jest-extensions`\n\n## Usage examples\n\n### equals\nChecks that object equals another object. Actually exposes built-in `toEqual` matcher.\n\n* matcher\n```ts\nimport '@anmiles/jest-extensions';\n\nexpect(object).equals(anotherObject);\n```\n\n* extension\n```ts\nimport '@anmiles/jest-extensions';\n\nexpect(spy).toHaveBeenCalledWith(expect.equals(obj));\n```\n\n* default export\n```ts\nimport { equals } from '@anmiles/jest-extensions';\n\nfunction customMatcher\u003cT\u003e(received: T, expected: T) : jest.CustomMatcherResult {\n\tconst receivedTransformed = someTransformFunction(received);\n\treturn equals(receivedTransformed, expected);\n}\n```\n\n### toBeFunction\nChecks that function being called with specified arguments will return expected value\n\n* matcher\n```ts\nimport '@anmiles/jest-extensions';\n\nexpect(func).toBeFunction((arg1, arg2) =\u003e expectedReturnValue);\n```\n\n* extension\n```ts\nimport '@anmiles/jest-extensions';\n\nexpect(invoker).toHaveBeenCalledWith(expect.toBeFunction((arg1, arg2) =\u003e expectedReturnValue));\n```\n\n* default export\n```ts\nimport { toBeFunction } from '@anmiles/jest-extensions';\n\nfunction customMatcher(received: (key: string, value: string) =\u003e Record\u003cstring, string\u003e, expectedValue: string) : jest.CustomMatcherResult {\n\treturn toBeFunction(received, [ 'key', 'value' ], { key : expectedValue });\n}\n```\n\n### toEqualStructure\nCompares objects with structure properties only (without functions). Type of expected object should not consist of any function-like properties.\n\n* matcher\n```ts\nimport '@anmiles/jest-extensions';\n\nexpect(obj).toEqualStructure(objWithoutFunctions);\n```\n\n* extension\n```ts\nimport '@anmiles/jest-extensions';\n\nexpect(func).toHaveBeenCalledWith(expect.toEqualStructure(obj));\n```\n\n* default export\n```ts\nimport { toEqualStructure, Structure } from '@anmiles/jest-extensions';\n\nfunction customMatcher\u003cT extends Record\u003cany, any\u003e\u003e(received: T, expected: Structure\u003cT\u003e) : jest.CustomMatcherResult {\n\treturn toEqualStructure(received, expected);\n}\n```\n\n* `toStructure` function\n```ts\nimport { toStructure } from '@anmiles/jest-extensions';\n\nconst objWithoutFunctions = toStructure(obj);\n```\n\n### toMatchFiles\nReads directory recursively and compares the list of files and their contents with expected object.\n\n* matcher\n```ts\nimport '@anmiles/jest-extensions';\n\nexpect(dirPath).toMatchFiles({ 'file': 'content', 'subdir/file2': 'content2' });\n```\n\n* extension\n```ts\nimport '@anmiles/jest-extensions';\n\nexpect(targetDir).toEqual(expect.toMatchFiles({ 'file': 'content', 'subdir/file2': 'content2' }));\n```\n\n* default export\n```ts\nimport { toMatchFiles } from '@anmiles/jest-extensions';\n\nfunction customMatcher\u003cT extends string\u003e(directoryPath: T, expected: Record\u003cT, string\u003e): jest.CustomMatcherResult {\n\treturn toMatchFiles(directoryPath, expected);\n}\n```\n\n### mockPartial\nMimics partial type as an underlying type when need to mock object with only part of required properties.\nDo not expects required properties to be specified, but type-check any specified properties to match original type.\n_This is not type-safe and should be used only in tests._\n\n```ts\nimport { mockPartial } from '@anmiles/jest-extensions';\n\ntype TestType = {\n\trequiredStr: string;\n\trequiredNum: number;\n\toptionalBool?: boolean;\n};\n\n// Valid: only one required property specified, but specified correctly\nconst partial1: TestType = mockPartial\u003cTestType\u003e({\n\trequiredStr: 'test',\n});\n\n// Valid: no required properties specified\nconst partial2: TestType = mockPartial\u003cTestType\u003e({});\n\n// Not valid: unknown properties specified\nconst partial3: TestType = mockPartial\u003cTestType\u003e({\n\tunknownProp: 'value',\n});\n\n// Not valid: known properties of wrong type specified \nconst partial3: TestType = mockPartial\u003cTestType\u003e({\n\trequiredStr: 5,\n});\n```\n\n### mockFS\n_Removed in favor of `mock-fs` package._\n_Refer to [this diff](https://github.com/anmiles/prototypes/commit/db74a55b223169b99284aa4ff27c7adf1629ff1b#diff-bbb8ca3bbb668a3e236b87fda1f06d7a41dbeed055dbfe6bf1892d7f4fefe49eL433) for example of replacement._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanmiles%2Fjest-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanmiles%2Fjest-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanmiles%2Fjest-extensions/lists"}