Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: spies #162

Merged
merged 32 commits into from
May 26, 2022
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
165d38f
feat(spies): initial commit
crookse Apr 21, 2022
6e58b29
tmp: spy on method
crookse Apr 21, 2022
ed6cb96
chore: add spies to esm build
crookse Apr 21, 2022
2f829e8
fix(errors): ignore toBeCalled in error stack trace
crookse Apr 24, 2022
7f02c2d
feat(method_verifier): make expectedCalls optional in toBeCalled(), a…
crookse Apr 24, 2022
02ceb3f
feat(errors): add SpyError
crookse Apr 24, 2022
e3d3446
chore(mod): add file marker comments to separate test double logic
crookse Apr 24, 2022
7a8efe4
refactor(spies): semantics; types; interfaces; conslidation
crookse Apr 24, 2022
cddb71e
chore: DRYing verifiers
crookse Apr 24, 2022
f15ab73
chore: update build process to include all new files
crookse Apr 26, 2022
00551a2
chore: hella clean up -- docblocks; DRY; early returns; abstraction
crookse Apr 26, 2022
73f67a5
feat(types): add Callable type to describe functions
crookse Apr 26, 2022
63de8a8
chore: remove file markers
crookse Apr 26, 2022
a8da845
refactor(spies): improve type-hinting for function expression spy
crookse Apr 26, 2022
60d72b1
test(spies): test parameterized function expressions
crookse Apr 26, 2022
ce71033
chore: semantics; comments
crookse Apr 26, 2022
ca20a86
chore: stop jest from running everything
crookse Apr 26, 2022
ed89730
test(spies): cjs tests
crookse Apr 26, 2022
d832efb
test(spies): esm tests
crookse Apr 26, 2022
f4426b1
chore: lint; fm
crookse Apr 28, 2022
2823b2c
fix(verifiers): issues surfaced from tests
crookse Apr 28, 2022
ae42330
test(verifiers): function expression verifier and method verifier
crookse Apr 28, 2022
30413d2
test(errors): test that the VerificationError stack trace shows as ex…
crookse Apr 28, 2022
0620bc1
refactor: remove try-catch (not needed)
crookse Apr 30, 2022
c53938c
chore: make concise error stack code more readable; provide example
crookse Apr 30, 2022
9995208
Merge branch 'chore/dry-code' into feat/spies
crookse Apr 30, 2022
c0be6b5
fix: issue with original being constructed without constructor args
crookse May 1, 2022
0bbc639
fix: issue with original being constructed without constructor args
crookse May 1, 2022
f096f28
chore: deno lint
crookse May 1, 2022
2364a4a
fix: issue with error message stating expected arg as unexpected arg …
crookse May 8, 2022
8776cfe
fix: hide mock.toBeCalledWithArgs and .toBeCalledWithoutArgs() (these…
crookse May 8, 2022
f7cde32
fix(spies): show correct code that threw
crookse May 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(spies): improve type-hinting for function expression spy
crookse committed Apr 26, 2022
commit a8da8453639561d204284cf334b9d065fd1e16b8
11 changes: 7 additions & 4 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Constructor, MethodOf } from "./src/types.ts";
import type { Callable, Constructor, MethodOf } from "./src/types.ts";
import { MockBuilder } from "./src/mock/mock_builder.ts";
import { FakeBuilder } from "./src/fake/fake_builder.ts";
import { SpyBuilder } from "./src/spy/spy_builder.ts";
@@ -84,12 +84,15 @@ export function Mock<T>(constructorFn: Constructor<T>): MockBuilder<T> {
*
* @returns The original function expression with spying capabilities.
*/
export function Spy<ReturnValue>(
export function Spy<
OriginalFunction extends Callable<ReturnValue>,
ReturnValue,
>(
// deno-lint-ignore no-explicit-any
functionExpression: (...args: any[]) => ReturnValue,
functionExpression: OriginalFunction,
returnValue?: ReturnValue,
// deno-lint-ignore no-explicit-any
): Interfaces.ISpyStubFunctionExpression & ((...args: any[]) => ReturnValue);
): Interfaces.ISpyStubFunctionExpression & OriginalFunction;

/**
* Create a spy out of an object's method.