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

Mock free functions #140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

johanblumenberg
Copy link
Contributor

@johanblumenberg johanblumenberg commented May 25, 2019

Mock free functions, without the need for any class to mock

Example:

let fn: (a: number, b: string) => number = fnmock();
when(fn(10, 'hello')).thenReturn(5);

instance(fn)(10, 'hello'); // returns 5

verify(fn(10, 'hello')).called();

Typescript 3.0+ is required for matching rest args to a tuple type, in this function signature:

export function fnmock<R, T extends any[]>(): (...args: T) => R {

@codecov-io
Copy link

Codecov Report

Merging #140 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #140      +/-   ##
========================================
+ Coverage   94.93%    95%   +0.06%     
========================================
  Files          34     34              
  Lines         612    620       +8     
  Branches       71     71              
========================================
+ Hits          581    589       +8     
  Misses         22     22              
  Partials        9      9
Impacted Files Coverage Δ
src/ts-mockito.ts 97.1% <100%> (+0.38%) ⬆️
src/Mock.ts 95.86% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 245892c...4cfb8fc. Read the comment docs.

@pelepelin
Copy link

Is there really no way to mock an unbound function at the moment?
This is much needed functionality then.

I don't like the name fnmock though, it's not in style with other names. Could it be possible to use mock(Function) or rename to functionMock?

@henrikra
Copy link

Can we resolve conflicts and get this in? @NagRock

@NagRock NagRock closed this Jul 6, 2021
@NagRock NagRock reopened this Jul 6, 2021
@codecov-commenter
Copy link

codecov-commenter commented Jul 6, 2021

Codecov Report

Merging #140 (4cfb8fc) into master (245892c) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #140      +/-   ##
==========================================
+ Coverage   94.93%   95.00%   +0.06%     
==========================================
  Files          34       34              
  Lines         612      620       +8     
  Branches       71       71              
==========================================
+ Hits          581      589       +8     
  Misses         22       22              
  Partials        9        9              
Impacted Files Coverage Δ
src/Mock.ts 95.86% <100.00%> (ø)
src/ts-mockito.ts 97.10% <100.00%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 245892c...4cfb8fc. Read the comment docs.

@awweather
Copy link

Can we get this merged in please?

@alejandrotineo
Copy link

alejandrotineo commented Nov 17, 2021

I really hope that we can get this merged!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants