@zudojs/testing 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/assertions/errorAssertions.core.d.ts +37 -0
- package/dist/assertions/errorAssertions.core.d.ts.map +1 -0
- package/dist/assertions/errorAssertions.core.js +82 -0
- package/dist/assertions/errorAssertions.core.js.map +1 -0
- package/dist/assertions/eventAssertions.core.d.ts +44 -0
- package/dist/assertions/eventAssertions.core.d.ts.map +1 -0
- package/dist/assertions/eventAssertions.core.js +63 -0
- package/dist/assertions/eventAssertions.core.js.map +1 -0
- package/dist/assertions/httpAssertions.core.d.ts +54 -0
- package/dist/assertions/httpAssertions.core.d.ts.map +1 -0
- package/dist/assertions/httpAssertions.core.js +80 -0
- package/dist/assertions/httpAssertions.core.js.map +1 -0
- package/dist/assertions/index.d.ts +9 -0
- package/dist/assertions/index.d.ts.map +1 -0
- package/dist/assertions/index.js +9 -0
- package/dist/assertions/index.js.map +1 -0
- package/dist/cleanupManager/cleanupManager.core.d.ts +54 -0
- package/dist/cleanupManager/cleanupManager.core.d.ts.map +1 -0
- package/dist/cleanupManager/cleanupManager.core.js +60 -0
- package/dist/cleanupManager/cleanupManager.core.js.map +1 -0
- package/dist/cleanupManager/index.d.ts +8 -0
- package/dist/cleanupManager/index.d.ts.map +1 -0
- package/dist/cleanupManager/index.js +7 -0
- package/dist/cleanupManager/index.js.map +1 -0
- package/dist/fixtures/eventFixtures.core.d.ts +53 -0
- package/dist/fixtures/eventFixtures.core.d.ts.map +1 -0
- package/dist/fixtures/eventFixtures.core.js +59 -0
- package/dist/fixtures/eventFixtures.core.js.map +1 -0
- package/dist/fixtures/index.d.ts +10 -0
- package/dist/fixtures/index.d.ts.map +1 -0
- package/dist/fixtures/index.js +8 -0
- package/dist/fixtures/index.js.map +1 -0
- package/dist/fixtures/messageFixtures.core.d.ts +53 -0
- package/dist/fixtures/messageFixtures.core.d.ts.map +1 -0
- package/dist/fixtures/messageFixtures.core.js +59 -0
- package/dist/fixtures/messageFixtures.core.js.map +1 -0
- package/dist/httpTesting/httpRequest.core.d.ts +69 -0
- package/dist/httpTesting/httpRequest.core.d.ts.map +1 -0
- package/dist/httpTesting/httpRequest.core.js +114 -0
- package/dist/httpTesting/httpRequest.core.js.map +1 -0
- package/dist/httpTesting/httpResponse.core.d.ts +20 -0
- package/dist/httpTesting/httpResponse.core.d.ts.map +1 -0
- package/dist/httpTesting/httpResponse.core.js +77 -0
- package/dist/httpTesting/httpResponse.core.js.map +1 -0
- package/dist/httpTesting/httpResponse.helpers.d.ts +24 -0
- package/dist/httpTesting/httpResponse.helpers.d.ts.map +1 -0
- package/dist/httpTesting/httpResponse.helpers.js +41 -0
- package/dist/httpTesting/httpResponse.helpers.js.map +1 -0
- package/dist/httpTesting/httpResponse.type.d.ts +25 -0
- package/dist/httpTesting/httpResponse.type.d.ts.map +1 -0
- package/dist/httpTesting/httpResponse.type.js +7 -0
- package/dist/httpTesting/httpResponse.type.js.map +1 -0
- package/dist/httpTesting/httpStatusCode.type.d.ts +10 -0
- package/dist/httpTesting/httpStatusCode.type.d.ts.map +1 -0
- package/dist/httpTesting/httpStatusCode.type.js +9 -0
- package/dist/httpTesting/httpStatusCode.type.js.map +1 -0
- package/dist/httpTesting/index.d.ts +11 -0
- package/dist/httpTesting/index.d.ts.map +1 -0
- package/dist/httpTesting/index.js +9 -0
- package/dist/httpTesting/index.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/mocking/index.d.ts +11 -0
- package/dist/mocking/index.d.ts.map +1 -0
- package/dist/mocking/index.js +9 -0
- package/dist/mocking/index.js.map +1 -0
- package/dist/mocking/mockFn.core.d.ts +40 -0
- package/dist/mocking/mockFn.core.d.ts.map +1 -0
- package/dist/mocking/mockFn.core.js +104 -0
- package/dist/mocking/mockFn.core.js.map +1 -0
- package/dist/mocking/spy.core.d.ts +66 -0
- package/dist/mocking/spy.core.d.ts.map +1 -0
- package/dist/mocking/spy.core.js +100 -0
- package/dist/mocking/spy.core.js.map +1 -0
- package/dist/mocking/stub.core.d.ts +56 -0
- package/dist/mocking/stub.core.d.ts.map +1 -0
- package/dist/mocking/stub.core.js +77 -0
- package/dist/mocking/stub.core.js.map +1 -0
- package/dist/spyLogger/index.d.ts +8 -0
- package/dist/spyLogger/index.d.ts.map +1 -0
- package/dist/spyLogger/index.js +7 -0
- package/dist/spyLogger/index.js.map +1 -0
- package/dist/spyLogger/spyLogger.core.d.ts +16 -0
- package/dist/spyLogger/spyLogger.core.d.ts.map +1 -0
- package/dist/spyLogger/spyLogger.core.js +69 -0
- package/dist/spyLogger/spyLogger.core.js.map +1 -0
- package/dist/spyLogger/spyLogger.type.d.ts +23 -0
- package/dist/spyLogger/spyLogger.type.d.ts.map +1 -0
- package/dist/spyLogger/spyLogger.type.js +7 -0
- package/dist/spyLogger/spyLogger.type.js.map +1 -0
- package/dist/testApplication/index.d.ts +8 -0
- package/dist/testApplication/index.d.ts.map +1 -0
- package/dist/testApplication/index.js +7 -0
- package/dist/testApplication/index.js.map +1 -0
- package/dist/testApplication/testApplication.core.d.ts +49 -0
- package/dist/testApplication/testApplication.core.d.ts.map +1 -0
- package/dist/testApplication/testApplication.core.js +51 -0
- package/dist/testApplication/testApplication.core.js.map +1 -0
- package/dist/testClock/index.d.ts +8 -0
- package/dist/testClock/index.d.ts.map +1 -0
- package/dist/testClock/index.js +7 -0
- package/dist/testClock/index.js.map +1 -0
- package/dist/testClock/testClock.core.d.ts +54 -0
- package/dist/testClock/testClock.core.d.ts.map +1 -0
- package/dist/testClock/testClock.core.js +57 -0
- package/dist/testClock/testClock.core.js.map +1 -0
- package/dist/testConfig/index.d.ts +8 -0
- package/dist/testConfig/index.d.ts.map +1 -0
- package/dist/testConfig/index.js +7 -0
- package/dist/testConfig/index.js.map +1 -0
- package/dist/testConfig/testConfig.core.d.ts +58 -0
- package/dist/testConfig/testConfig.core.d.ts.map +1 -0
- package/dist/testConfig/testConfig.core.js +53 -0
- package/dist/testConfig/testConfig.core.js.map +1 -0
- package/dist/testContainer/index.d.ts +8 -0
- package/dist/testContainer/index.d.ts.map +1 -0
- package/dist/testContainer/index.js +7 -0
- package/dist/testContainer/index.js.map +1 -0
- package/dist/testContainer/testContainer.core.d.ts +60 -0
- package/dist/testContainer/testContainer.core.d.ts.map +1 -0
- package/dist/testContainer/testContainer.core.js +47 -0
- package/dist/testContainer/testContainer.core.js.map +1 -0
- package/dist/testContext/index.d.ts +10 -0
- package/dist/testContext/index.d.ts.map +1 -0
- package/dist/testContext/index.js +8 -0
- package/dist/testContext/index.js.map +1 -0
- package/dist/testContext/testContext.core.d.ts +32 -0
- package/dist/testContext/testContext.core.d.ts.map +1 -0
- package/dist/testContext/testContext.core.js +28 -0
- package/dist/testContext/testContext.core.js.map +1 -0
- package/dist/testContext/testContext.recorder.core.d.ts +19 -0
- package/dist/testContext/testContext.recorder.core.d.ts.map +1 -0
- package/dist/testContext/testContext.recorder.core.js +74 -0
- package/dist/testContext/testContext.recorder.core.js.map +1 -0
- package/dist/testContext/testContext.recorder.type.d.ts +59 -0
- package/dist/testContext/testContext.recorder.type.d.ts.map +1 -0
- package/dist/testContext/testContext.recorder.type.js +7 -0
- package/dist/testContext/testContext.recorder.type.js.map +1 -0
- package/dist/testEventBus/index.d.ts +8 -0
- package/dist/testEventBus/index.d.ts.map +1 -0
- package/dist/testEventBus/index.js +7 -0
- package/dist/testEventBus/index.js.map +1 -0
- package/dist/testEventBus/testEventBus.core.d.ts +61 -0
- package/dist/testEventBus/testEventBus.core.d.ts.map +1 -0
- package/dist/testEventBus/testEventBus.core.js +61 -0
- package/dist/testEventBus/testEventBus.core.js.map +1 -0
- package/dist/testMessageBus/index.d.ts +8 -0
- package/dist/testMessageBus/index.d.ts.map +1 -0
- package/dist/testMessageBus/index.js +7 -0
- package/dist/testMessageBus/index.js.map +1 -0
- package/dist/testMessageBus/testMessageBus.core.d.ts +61 -0
- package/dist/testMessageBus/testMessageBus.core.d.ts.map +1 -0
- package/dist/testMessageBus/testMessageBus.core.js +61 -0
- package/dist/testMessageBus/testMessageBus.core.js.map +1 -0
- package/dist/testQueue/index.d.ts +8 -0
- package/dist/testQueue/index.d.ts.map +1 -0
- package/dist/testQueue/index.js +7 -0
- package/dist/testQueue/index.js.map +1 -0
- package/dist/testQueue/testQueue.core.d.ts +46 -0
- package/dist/testQueue/testQueue.core.d.ts.map +1 -0
- package/dist/testQueue/testQueue.core.js +36 -0
- package/dist/testQueue/testQueue.core.js.map +1 -0
- package/dist/testSerialization/index.d.ts +7 -0
- package/dist/testSerialization/index.d.ts.map +1 -0
- package/dist/testSerialization/index.js +7 -0
- package/dist/testSerialization/index.js.map +1 -0
- package/dist/testSerialization/serializationAssertions.core.d.ts +37 -0
- package/dist/testSerialization/serializationAssertions.core.d.ts.map +1 -0
- package/dist/testSerialization/serializationAssertions.core.js +63 -0
- package/dist/testSerialization/serializationAssertions.core.js.map +1 -0
- package/dist/testStorage/index.d.ts +7 -0
- package/dist/testStorage/index.d.ts.map +1 -0
- package/dist/testStorage/index.js +7 -0
- package/dist/testStorage/index.js.map +1 -0
- package/dist/testStorage/testStorageMemory.core.d.ts +30 -0
- package/dist/testStorage/testStorageMemory.core.d.ts.map +1 -0
- package/dist/testStorage/testStorageMemory.core.js +52 -0
- package/dist/testStorage/testStorageMemory.core.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/testing — HTTP status code type.
|
|
3
|
+
*
|
|
4
|
+
* Local definition of HTTPStatusCode for testing purposes.
|
|
5
|
+
* When @zudojs/http builds cleanly, this should be replaced
|
|
6
|
+
* with an import from @zudojs/http.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=httpStatusCode.type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpStatusCode.type.js","sourceRoot":"","sources":["../../src/httpTesting/httpStatusCode.type.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/testing — HTTP testing helpers.
|
|
3
|
+
*
|
|
4
|
+
* Request and response builders for HTTP testing.
|
|
5
|
+
*/
|
|
6
|
+
export { createTestHTTPRequest, createHTTPRequest, } from "./httpRequest.core.js";
|
|
7
|
+
export type { HTTPRequestBuilder, TestHTTPRequest, } from "./httpRequest.core.js";
|
|
8
|
+
export { createTestHTTPResponse } from "./httpResponse.core.js";
|
|
9
|
+
export type { HTTPResponseBuilder, TestHTTPResponse, } from "./httpResponse.type.js";
|
|
10
|
+
export { createHTTPResponse, jsonResponse, createdResponse, noContentResponse, badRequestResponse, notFoundResponse, serverErrorResponse, } from "./httpResponse.helpers.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/httpTesting/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACV,kBAAkB,EAClB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,YAAY,EACV,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/testing — HTTP testing helpers.
|
|
3
|
+
*
|
|
4
|
+
* Request and response builders for HTTP testing.
|
|
5
|
+
*/
|
|
6
|
+
export { createTestHTTPRequest, createHTTPRequest, } from "./httpRequest.core.js";
|
|
7
|
+
export { createTestHTTPResponse } from "./httpResponse.core.js";
|
|
8
|
+
export { createHTTPResponse, jsonResponse, createdResponse, noContentResponse, badRequestResponse, notFoundResponse, serverErrorResponse, } from "./httpResponse.helpers.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/httpTesting/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAO/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAOhE,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/testing
|
|
3
|
+
*
|
|
4
|
+
* Testing infrastructure for the Zudojs framework.
|
|
5
|
+
* Provides test containers, fakes, fixtures, mocks, assertions,
|
|
6
|
+
* and utilities for consistent testing across all Zudojs packages.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./cleanupManager/index.js";
|
|
9
|
+
export * from "./testClock/index.js";
|
|
10
|
+
export * from "./testContext/index.js";
|
|
11
|
+
export * from "./testContainer/index.js";
|
|
12
|
+
export * from "./spyLogger/index.js";
|
|
13
|
+
export * from "./testConfig/index.js";
|
|
14
|
+
export * from "./testEventBus/index.js";
|
|
15
|
+
export * from "./testMessageBus/index.js";
|
|
16
|
+
export * from "./testQueue/index.js";
|
|
17
|
+
export * from "./httpTesting/index.js";
|
|
18
|
+
export * from "./mocking/index.js";
|
|
19
|
+
export * from "./fixtures/index.js";
|
|
20
|
+
export * from "./assertions/index.js";
|
|
21
|
+
export * from "./testApplication/index.js";
|
|
22
|
+
export * from "./testSerialization/index.js";
|
|
23
|
+
export * from "./testStorage/index.js";
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/testing
|
|
3
|
+
*
|
|
4
|
+
* Testing infrastructure for the Zudojs framework.
|
|
5
|
+
* Provides test containers, fakes, fixtures, mocks, assertions,
|
|
6
|
+
* and utilities for consistent testing across all Zudojs packages.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./cleanupManager/index.js";
|
|
9
|
+
export * from "./testClock/index.js";
|
|
10
|
+
export * from "./testContext/index.js";
|
|
11
|
+
export * from "./testContainer/index.js";
|
|
12
|
+
export * from "./spyLogger/index.js";
|
|
13
|
+
export * from "./testConfig/index.js";
|
|
14
|
+
export * from "./testEventBus/index.js";
|
|
15
|
+
export * from "./testMessageBus/index.js";
|
|
16
|
+
export * from "./testQueue/index.js";
|
|
17
|
+
export * from "./httpTesting/index.js";
|
|
18
|
+
export * from "./mocking/index.js";
|
|
19
|
+
export * from "./fixtures/index.js";
|
|
20
|
+
export * from "./assertions/index.js";
|
|
21
|
+
export * from "./testApplication/index.js";
|
|
22
|
+
export * from "./testSerialization/index.js";
|
|
23
|
+
export * from "./testStorage/index.js";
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mocking utilities.
|
|
3
|
+
*
|
|
4
|
+
* Mock functions, spies, and stubs for testing.
|
|
5
|
+
*/
|
|
6
|
+
export { createMockFn } from "./mockFn.core.js";
|
|
7
|
+
export { createSpyFn, createSpyMethod } from "./spy.core.js";
|
|
8
|
+
export { createStub, createStubClass } from "./stub.core.js";
|
|
9
|
+
export type { MockFn } from "./mockFn.core.js";
|
|
10
|
+
export type { SpyFn, SpyMethod } from "./spy.core.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mocking/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE7D,YAAY,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mocking utilities.
|
|
3
|
+
*
|
|
4
|
+
* Mock functions, spies, and stubs for testing.
|
|
5
|
+
*/
|
|
6
|
+
export { createMockFn } from "./mockFn.core.js";
|
|
7
|
+
export { createSpyFn, createSpyMethod } from "./spy.core.js";
|
|
8
|
+
export { createStub, createStubClass } from "./stub.core.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mocking/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock function utilities.
|
|
3
|
+
*
|
|
4
|
+
* Creates mock functions that record calls and return configured values.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A mock function that records calls and returns configured values.
|
|
8
|
+
*/
|
|
9
|
+
export interface MockFn<TArgs extends readonly unknown[] = unknown[], TResult = unknown> {
|
|
10
|
+
(...args: TArgs): TResult;
|
|
11
|
+
readonly calls: readonly TArgs[];
|
|
12
|
+
readonly results: readonly TResult[];
|
|
13
|
+
readonly invoked: boolean;
|
|
14
|
+
readonly callCount: number;
|
|
15
|
+
mockReturnValue: (value: TResult) => void;
|
|
16
|
+
mockResolvedValue: (value: TResult) => void;
|
|
17
|
+
mockRejectedValue: (error: unknown) => void;
|
|
18
|
+
mockImplementation: (fn: (...args: TArgs) => TResult) => void;
|
|
19
|
+
mockReset: () => void;
|
|
20
|
+
mockClear: () => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a mock function.
|
|
24
|
+
*
|
|
25
|
+
* @param defaultReturnValue - Optional default return value.
|
|
26
|
+
* @returns A MockFn instance.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const mockFn = createMockFn<string[], void>();
|
|
31
|
+
*
|
|
32
|
+
* mockFn("hello", "world");
|
|
33
|
+
*
|
|
34
|
+
* expect(mockFn.calls).toHaveLength(1);
|
|
35
|
+
* expect(mockFn.calls[0]).toEqual(["hello", "world"]);
|
|
36
|
+
* expect(mockFn.callCount).toBe(1);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function createMockFn<TArgs extends readonly unknown[] = unknown[], TResult = unknown>(defaultReturnValue?: TResult): MockFn<TArgs, TResult>;
|
|
40
|
+
//# sourceMappingURL=mockFn.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockFn.core.d.ts","sourceRoot":"","sources":["../../src/mocking/mockFn.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,MAAM,CACrB,KAAK,SAAS,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,EAC5C,OAAO,GAAG,OAAO;IAEjB,CAAC,GAAG,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,KAAK,EAAE,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1C,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5C,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5C,kBAAkB,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,KAAK,IAAI,CAAC;IAC9D,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAC1B,KAAK,SAAS,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,EAC5C,OAAO,GAAG,OAAO,EACjB,kBAAkB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAiGtD"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock function utilities.
|
|
3
|
+
*
|
|
4
|
+
* Creates mock functions that record calls and return configured values.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a mock function.
|
|
8
|
+
*
|
|
9
|
+
* @param defaultReturnValue - Optional default return value.
|
|
10
|
+
* @returns A MockFn instance.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const mockFn = createMockFn<string[], void>();
|
|
15
|
+
*
|
|
16
|
+
* mockFn("hello", "world");
|
|
17
|
+
*
|
|
18
|
+
* expect(mockFn.calls).toHaveLength(1);
|
|
19
|
+
* expect(mockFn.calls[0]).toEqual(["hello", "world"]);
|
|
20
|
+
* expect(mockFn.callCount).toBe(1);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function createMockFn(defaultReturnValue) {
|
|
24
|
+
const calls = [];
|
|
25
|
+
const results = [];
|
|
26
|
+
let implementation;
|
|
27
|
+
let returnValue = defaultReturnValue;
|
|
28
|
+
let resolvedValue;
|
|
29
|
+
let rejectedValue;
|
|
30
|
+
let shouldReject = false;
|
|
31
|
+
const mock = ((...args) => {
|
|
32
|
+
calls.push(args);
|
|
33
|
+
if (shouldReject) {
|
|
34
|
+
throw rejectedValue;
|
|
35
|
+
}
|
|
36
|
+
if (resolvedValue !== undefined) {
|
|
37
|
+
results.push(resolvedValue);
|
|
38
|
+
return resolvedValue;
|
|
39
|
+
}
|
|
40
|
+
if (implementation) {
|
|
41
|
+
const result = implementation(...args);
|
|
42
|
+
results.push(result);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
if (returnValue !== undefined) {
|
|
46
|
+
results.push(returnValue);
|
|
47
|
+
return returnValue;
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(mock, "calls", {
|
|
52
|
+
get: () => calls,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(mock, "results", {
|
|
56
|
+
get: () => results,
|
|
57
|
+
enumerable: true,
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(mock, "invoked", {
|
|
60
|
+
get: () => calls.length > 0,
|
|
61
|
+
enumerable: true,
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(mock, "callCount", {
|
|
64
|
+
get: () => calls.length,
|
|
65
|
+
enumerable: true,
|
|
66
|
+
});
|
|
67
|
+
mock.mockReturnValue = (value) => {
|
|
68
|
+
returnValue = value;
|
|
69
|
+
resolvedValue = undefined;
|
|
70
|
+
shouldReject = false;
|
|
71
|
+
};
|
|
72
|
+
mock.mockResolvedValue = (value) => {
|
|
73
|
+
resolvedValue = value;
|
|
74
|
+
returnValue = undefined;
|
|
75
|
+
shouldReject = false;
|
|
76
|
+
};
|
|
77
|
+
mock.mockRejectedValue = (error) => {
|
|
78
|
+
rejectedValue = error;
|
|
79
|
+
shouldReject = true;
|
|
80
|
+
returnValue = undefined;
|
|
81
|
+
resolvedValue = undefined;
|
|
82
|
+
};
|
|
83
|
+
mock.mockImplementation = (fn) => {
|
|
84
|
+
implementation = fn;
|
|
85
|
+
returnValue = undefined;
|
|
86
|
+
resolvedValue = undefined;
|
|
87
|
+
shouldReject = false;
|
|
88
|
+
};
|
|
89
|
+
mock.mockReset = () => {
|
|
90
|
+
calls.length = 0;
|
|
91
|
+
results.length = 0;
|
|
92
|
+
implementation = undefined;
|
|
93
|
+
returnValue = defaultReturnValue;
|
|
94
|
+
resolvedValue = undefined;
|
|
95
|
+
rejectedValue = undefined;
|
|
96
|
+
shouldReject = false;
|
|
97
|
+
};
|
|
98
|
+
mock.mockClear = () => {
|
|
99
|
+
calls.length = 0;
|
|
100
|
+
results.length = 0;
|
|
101
|
+
};
|
|
102
|
+
return mock;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=mockFn.core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockFn.core.js","sourceRoot":"","sources":["../../src/mocking/mockFn.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAsBH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAG1B,kBAA4B;IAC5B,MAAM,KAAK,GAAY,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAc,EAAE,CAAC;IAC9B,IAAI,cAAyD,CAAC;IAC9D,IAAI,WAAW,GAAwB,kBAAkB,CAAC;IAC1D,IAAI,aAAkC,CAAC;IACvC,IAAI,aAAsB,CAAC;IAC3B,IAAI,YAAY,GAAG,KAAK,CAAC;IAEzB,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,IAAW,EAAW,EAAE;QACxC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEjB,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM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|
+
* A spy that wraps an existing function.
|
|
8
|
+
*/
|
|
9
|
+
export interface SpyFn<TArgs extends readonly unknown[] = unknown[], TResult = unknown> {
|
|
10
|
+
(...args: TArgs): TResult;
|
|
11
|
+
readonly original: (...args: TArgs) => TResult;
|
|
12
|
+
readonly calls: readonly TArgs[];
|
|
13
|
+
readonly results: readonly TResult[];
|
|
14
|
+
readonly callCount: number;
|
|
15
|
+
restore: () => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a spy that wraps an existing function.
|
|
19
|
+
*
|
|
20
|
+
* @param fn - The function to spy on.
|
|
21
|
+
* @returns A SpyFn instance.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const original = (a: number, b: number) => a + b;
|
|
26
|
+
* const spy = createSpyFn(original);
|
|
27
|
+
*
|
|
28
|
+
* expect(spy(1, 2)).toBe(3);
|
|
29
|
+
* expect(spy.calls).toHaveLength(1);
|
|
30
|
+
* expect(spy.calls[0]).toEqual([1, 2]);
|
|
31
|
+
*
|
|
32
|
+
* spy.restore();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function createSpyFn<TArgs extends readonly unknown[] = unknown[], TResult = unknown>(fn: (...args: TArgs) => TResult): SpyFn<TArgs, TResult>;
|
|
36
|
+
/**
|
|
37
|
+
* A spy that wraps an object method.
|
|
38
|
+
*/
|
|
39
|
+
export interface SpyMethod<TObj, TMethod extends keyof TObj> {
|
|
40
|
+
readonly object: TObj;
|
|
41
|
+
readonly property: TMethod;
|
|
42
|
+
readonly calls: readonly unknown[][];
|
|
43
|
+
readonly callCount: number;
|
|
44
|
+
restore: () => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a spy on an object method.
|
|
48
|
+
*
|
|
49
|
+
* @param object - The object containing the method.
|
|
50
|
+
* @param property - The method name to spy on.
|
|
51
|
+
* @returns A SpyMethod instance.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const service = { save: (data: unknown) => ({ ...data, saved: true }) };
|
|
56
|
+
* const spy = createSpyMethod(service, "save");
|
|
57
|
+
*
|
|
58
|
+
* service.save({ id: "123" });
|
|
59
|
+
*
|
|
60
|
+
* expect(spy.calls).toHaveLength(1);
|
|
61
|
+
*
|
|
62
|
+
* spy.restore();
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function createSpyMethod<TObj, TMethod extends keyof TObj>(object: TObj, property: TMethod): SpyMethod<TObj, TMethod>;
|
|
66
|
+
//# sourceMappingURL=spy.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spy.core.d.ts","sourceRoot":"","sources":["../../src/mocking/spy.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,KAAK,CACpB,KAAK,SAAS,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,EAC5C,OAAO,GAAG,OAAO;IAEjB,CAAC,GAAG,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC;IAC/C,QAAQ,CAAC,KAAK,EAAE,SAAS,KAAK,EAAE,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CACzB,KAAK,SAAS,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,EAC5C,OAAO,GAAG,OAAO,EACjB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,GAAG,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAsCxD;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,IAAI,EAAE,OAAO,SAAS,MAAM,IAAI;IACzD,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,EAAE,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,SAAS,MAAM,IAAI,EAC9D,MAAM,EAAE,IAAI,EACZ,QAAQ,EAAE,OAAO,GAChB,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CA8B1B"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spy utilities.
|
|
3
|
+
*
|
|
4
|
+
* Wraps existing functions to record calls while preserving behavior.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a spy that wraps an existing function.
|
|
8
|
+
*
|
|
9
|
+
* @param fn - The function to spy on.
|
|
10
|
+
* @returns A SpyFn instance.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const original = (a: number, b: number) => a + b;
|
|
15
|
+
* const spy = createSpyFn(original);
|
|
16
|
+
*
|
|
17
|
+
* expect(spy(1, 2)).toBe(3);
|
|
18
|
+
* expect(spy.calls).toHaveLength(1);
|
|
19
|
+
* expect(spy.calls[0]).toEqual([1, 2]);
|
|
20
|
+
*
|
|
21
|
+
* spy.restore();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function createSpyFn(fn) {
|
|
25
|
+
const calls = [];
|
|
26
|
+
const results = [];
|
|
27
|
+
const spy = ((...args) => {
|
|
28
|
+
calls.push(args);
|
|
29
|
+
const result = fn(...args);
|
|
30
|
+
results.push(result);
|
|
31
|
+
return result;
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(spy, "original", {
|
|
34
|
+
value: fn,
|
|
35
|
+
writable: false,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(spy, "calls", {
|
|
39
|
+
get: () => calls,
|
|
40
|
+
enumerable: true,
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(spy, "results", {
|
|
43
|
+
get: () => results,
|
|
44
|
+
enumerable: true,
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(spy, "callCount", {
|
|
47
|
+
get: () => calls.length,
|
|
48
|
+
enumerable: true,
|
|
49
|
+
});
|
|
50
|
+
spy.restore = () => {
|
|
51
|
+
calls.length = 0;
|
|
52
|
+
results.length = 0;
|
|
53
|
+
};
|
|
54
|
+
return spy;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a spy on an object method.
|
|
58
|
+
*
|
|
59
|
+
* @param object - The object containing the method.
|
|
60
|
+
* @param property - The method name to spy on.
|
|
61
|
+
* @returns A SpyMethod instance.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const service = { save: (data: unknown) => ({ ...data, saved: true }) };
|
|
66
|
+
* const spy = createSpyMethod(service, "save");
|
|
67
|
+
*
|
|
68
|
+
* service.save({ id: "123" });
|
|
69
|
+
*
|
|
70
|
+
* expect(spy.calls).toHaveLength(1);
|
|
71
|
+
*
|
|
72
|
+
* spy.restore();
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export function createSpyMethod(object, property) {
|
|
76
|
+
const original = object[property];
|
|
77
|
+
const calls = [];
|
|
78
|
+
if (typeof original !== "function") {
|
|
79
|
+
throw new TypeError(`Property "${String(property)}" is not a function.`);
|
|
80
|
+
}
|
|
81
|
+
const originalFn = original;
|
|
82
|
+
object[property] = ((...args) => {
|
|
83
|
+
calls.push(args);
|
|
84
|
+
return originalFn(...args);
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
object,
|
|
88
|
+
property,
|
|
89
|
+
calls,
|
|
90
|
+
get callCount() {
|
|
91
|
+
return calls.length;
|
|
92
|
+
},
|
|
93
|
+
restore: () => {
|
|
94
|
+
object[property] =
|
|
95
|
+
original;
|
|
96
|
+
calls.length = 0;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=spy.core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spy.core.js","sourceRoot":"","sources":["../../src/mocking/spy.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAiBH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,WAAW,CAGzB,EAA+B;IAC/B,MAAM,KAAK,GAAY,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAc,EAAE,CAAC;IAE9B,MAAM,GAAG,GAAG,CAAC,CAAC,GAAG,IAAW,EAAW,EAAE;QACvC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,MAAM,CAAC;IAChB,CAAC,CAA0B,CAAC;IAE5B,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE;QACrC,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE;QAClC,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK;QAChB,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE;QACpC,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO;QAClB,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH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*
|
|
4
|
+
* Creates fake implementations of interfaces for testing.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a stub object from an interface.
|
|
8
|
+
*
|
|
9
|
+
* All methods return undefined by default. Override specific methods
|
|
10
|
+
* by passing an overrides object.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam T - The interface type to stub.
|
|
13
|
+
* @param overrides - Optional method implementations.
|
|
14
|
+
* @returns A stub object matching the interface.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* interface UserService {
|
|
19
|
+
* find(id: string): Promise<User | null>;
|
|
20
|
+
* create(data: CreateUserInput): Promise<User>;
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* const stub = createStub<UserService>({
|
|
24
|
+
* find: async (id) => ({ id, name: "Test" }),
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* expect(await stub.find("123")).toEqual({ id: "123", name: "Test" });
|
|
28
|
+
* expect(stub.create).toBeUndefined();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function createStub<T extends Record<string, unknown>>(overrides?: Partial<T>): T;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a stub class constructor.
|
|
34
|
+
*
|
|
35
|
+
* @typeParam T - The class type to stub.
|
|
36
|
+
* @param overrides - Optional property and method implementations.
|
|
37
|
+
* @returns A stub class constructor.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* class RealDatabase {
|
|
42
|
+
* async connect(): Promise<void> { /* real implementation *\/ }
|
|
43
|
+
* async query(sql: string): Promise<unknown[]> { /* real implementation *\/ }
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* const StubDatabase = createStubClass(RealDatabase, {
|
|
47
|
+
* connect: async () => {},
|
|
48
|
+
* query: async () => [],
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* const db = new StubDatabase();
|
|
52
|
+
* await db.connect();
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function createStubClass<T>(_OriginalClass: new (...args: unknown[]) => T, overrides?: Partial<T>): new () => T;
|
|
56
|
+
//# sourceMappingURL=stub.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub.core.d.ts","sourceRoot":"","sources":["../../src/mocking/stub.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1D,SAAS,GAAE,OAAO,CAAC,CAAC,CAAoB,GACvC,CAAC,CAgBH;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,cAAc,EAAE,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EAC7C,SAAS,GAAE,OAAO,CAAC,CAAC,CAAoB,GACvC,UAAU,CAAC,CAQb"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stub utilities.
|
|
3
|
+
*
|
|
4
|
+
* Creates fake implementations of interfaces for testing.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a stub object from an interface.
|
|
8
|
+
*
|
|
9
|
+
* All methods return undefined by default. Override specific methods
|
|
10
|
+
* by passing an overrides object.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam T - The interface type to stub.
|
|
13
|
+
* @param overrides - Optional method implementations.
|
|
14
|
+
* @returns A stub object matching the interface.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* interface UserService {
|
|
19
|
+
* find(id: string): Promise<User | null>;
|
|
20
|
+
* create(data: CreateUserInput): Promise<User>;
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* const stub = createStub<UserService>({
|
|
24
|
+
* find: async (id) => ({ id, name: "Test" }),
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* expect(await stub.find("123")).toEqual({ id: "123", name: "Test" });
|
|
28
|
+
* expect(stub.create).toBeUndefined();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function createStub(overrides = {}) {
|
|
32
|
+
return new Proxy({}, {
|
|
33
|
+
get(_target, prop, _receiver) {
|
|
34
|
+
const key = prop;
|
|
35
|
+
if (key in overrides) {
|
|
36
|
+
return overrides[key];
|
|
37
|
+
}
|
|
38
|
+
if (typeof prop === "symbol") {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return (..._args) => undefined;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a stub class constructor.
|
|
47
|
+
*
|
|
48
|
+
* @typeParam T - The class type to stub.
|
|
49
|
+
* @param overrides - Optional property and method implementations.
|
|
50
|
+
* @returns A stub class constructor.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* class RealDatabase {
|
|
55
|
+
* async connect(): Promise<void> { /* real implementation *\/ }
|
|
56
|
+
* async query(sql: string): Promise<unknown[]> { /* real implementation *\/ }
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* const StubDatabase = createStubClass(RealDatabase, {
|
|
60
|
+
* connect: async () => {},
|
|
61
|
+
* query: async () => [],
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* const db = new StubDatabase();
|
|
65
|
+
* await db.connect();
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function createStubClass(_OriginalClass, overrides = {}) {
|
|
69
|
+
return class {
|
|
70
|
+
constructor() {
|
|
71
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
72
|
+
this[key] = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=stub.core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub.core.js","sourceRoot":"","sources":["../../src/mocking/stub.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,UAAU,CACxB,SAAS,GAAe,EAAgB;IAExC,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE;QACxB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS;YAC1B,MAAM,GAAG,GAAG,IAAe,CAAC;YAE5B,IAAI,GAAG,IAAI,SAAS,EAAE,CAAC;gBACrB,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;YAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC7B,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,OAAO,CAAC,GAAG,KAAgB,EAAE,EAAE,CAAC,SAAS,CAAC;QAC5C,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,eAAe,CAC7B,cAA6C,EAC7C,SAAS,GAAe,EAAgB;IAExC,OAAO;QACL;YACE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;gBACpD,IAAgC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACjD,CAAC;QACH,CAAC;KACa,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spyLogger/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/spyLogger/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/testing — Spy logger for testing.
|
|
3
|
+
*
|
|
4
|
+
* Records all log calls for assertion without side effects.
|
|
5
|
+
*/
|
|
6
|
+
import type { LoggerLevel } from "@zudojs/logger";
|
|
7
|
+
import type { SpyLogger } from "./spyLogger.type.js";
|
|
8
|
+
/**
|
|
9
|
+
* Creates a spy logger that records all log calls.
|
|
10
|
+
*
|
|
11
|
+
* @param name - Logger name.
|
|
12
|
+
* @param level - Optional minimum level (defaults to TRACE = all).
|
|
13
|
+
* @returns A SpyLogger instance.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createSpyLogger(name?: string, level?: LoggerLevel): SpyLogger;
|
|
16
|
+
//# sourceMappingURL=spyLogger.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spyLogger.core.d.ts","sourceRoot":"","sources":["../../src/spyLogger/spyLogger.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EAIZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAW,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAY9D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,SAAS,EACb,KAAK,GAAE,WAA8B,GACpC,SAAS,CAkEX"}
|