Repository navigation
Added the "Top Level functions" section - #1061
Conversation
Explained how to mock top-level functions. Added a code example using the mockkStatic(KFunction<*>) overload.
|
Thanks! |
|
This change states that:
Which seems to contradict the documentation here: mockk/modules/mockk/src/jvmMain/kotlin/io/mockk/MockK.kt Lines 23 to 27 in 0fa0b26 |
|
You're right, it isn't the best wording choice... it doesn't express exactly what I meant. To start with I wasn't aware of this behavior, what I meant was that stubbing a function invocation wouldn't affect the others in the file, but yeah it doesn't make a lot of sense. So we should correct this to illustrate the actual behavior, that is any other mocks on the function's declaring class are canceled. This can be controlled if the mock is explicitly canceled after its usage, for example, once all the tests in a class execute. |
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [io.mockk:mockk](https://mockk.io) ([source](https://togithub.com/mockk/mockk)) | `1.13.4` -> `1.13.5` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>mockk/mockk</summary> ### [`v1.13.5`](https://togithub.com/mockk/mockk/releases/tag/1.13.5) #### What's Changed - Return the configured answers when no answer found by [@​maeserichar](https://togithub.com/maeserichar) in [https://github.com/mockk/mockk/pull/1032](https://togithub.com/mockk/mockk/pull/1032) - Recognize atLeast = 0 when mocked methods is never called by [@​hfxbse](https://togithub.com/hfxbse) in [https://github.com/mockk/mockk/pull/970](https://togithub.com/mockk/mockk/pull/970) - Update class declaration name to match with test class by [@​Sandhya2902](https://togithub.com/Sandhya2902) in [https://github.com/mockk/mockk/pull/1044](https://togithub.com/mockk/mockk/pull/1044) - Update to Junit 5 by [@​Sandhya2902](https://togithub.com/Sandhya2902) in [https://github.com/mockk/mockk/pull/1045](https://togithub.com/mockk/mockk/pull/1045) - Issue [#​997](https://togithub.com/mockk/mockk/issues/997) - Simulate garbage collected proxy by [@​ygaller](https://togithub.com/ygaller) in [https://github.com/mockk/mockk/pull/1052](https://togithub.com/mockk/mockk/pull/1052) - Enable Gradle build scan publishing by [@​Goooler](https://togithub.com/Goooler) in [https://github.com/mockk/mockk/pull/1060](https://togithub.com/mockk/mockk/pull/1060) - Added the "Top Level functions" section by [@​polarene](https://togithub.com/polarene) in [https://github.com/mockk/mockk/pull/1061](https://togithub.com/mockk/mockk/pull/1061) - corrected incongruent code in "Object mock" by [@​polarene](https://togithub.com/polarene) in [https://github.com/mockk/mockk/pull/1063](https://togithub.com/mockk/mockk/pull/1063) - Kotlin 1.8.20 by [@​SimonMarquis](https://togithub.com/SimonMarquis) in [https://github.com/mockk/mockk/pull/1047](https://togithub.com/mockk/mockk/pull/1047) #### New Contributors - [@​maeserichar](https://togithub.com/maeserichar) made their first contribution in [https://github.com/mockk/mockk/pull/1032](https://togithub.com/mockk/mockk/pull/1032) - [@​hfxbse](https://togithub.com/hfxbse) made their first contribution in [https://github.com/mockk/mockk/pull/970](https://togithub.com/mockk/mockk/pull/970) - [@​ygaller](https://togithub.com/ygaller) made their first contribution in [https://github.com/mockk/mockk/pull/1052](https://togithub.com/mockk/mockk/pull/1052) - [@​Goooler](https://togithub.com/Goooler) made their first contribution in [https://github.com/mockk/mockk/pull/1060](https://togithub.com/mockk/mockk/pull/1060) **Full Changelog**: mockk/mockk@v1.13.4...1.13.5 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/dooboolab-community/react-native-iap). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS45OC40IiwidXBkYXRlZEluVmVyIjoiMzUuMTMxLjAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Explained how to mock top-level functions. Added a code example using the mockkStatic(KFunction<*>) overload.