Skip to content

Mock free functions - #140

Open
johanblumenberg wants to merge 2 commits into
NagRock:masterfrom
johanblumenberg:fnmock
Open

Mock free functions#140
johanblumenberg wants to merge 2 commits into
NagRock:masterfrom
johanblumenberg:fnmock

Conversation

@johanblumenberg

@johanblumenberg johanblumenberg commented May 25, 2019

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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

codecov-commenter commented Jul 6, 2021

Copy link
Copy Markdown

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
Copy Markdown

Can we get this merged in please?

@alejandrotineo

alejandrotineo commented Nov 17, 2021

Copy link
Copy Markdown

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.

8 participants