Skip to content

Added the "Top Level functions" section - #1061

Merged
Raibaz merged 1 commit into
mockk:masterfrom
polarene:patch-1
Mar 6, 2023
Merged

Raibaz merged 1 commit into
mockk:masterfrom
polarene:patch-1

Conversation

@polarene

@polarene polarene commented Mar 6, 2023

Copy link
Copy Markdown
Contributor

Explained how to mock top-level functions. Added a code example using the mockkStatic(KFunction<*>) overload.

Explained how to mock top-level functions. Added a code example using the mockkStatic(KFunction<*>) overload.
@Raibaz

Raibaz commented Mar 6, 2023

Copy link
Copy Markdown
Collaborator

Thanks!

@Raibaz
Raibaz merged commit 0fa0b26 into mockk:master Mar 6, 2023
@mcclurej06

Copy link
Copy Markdown

This change states that:

Mocking a function doesn't affect other functions declared in the same file.

Which seems to contradict the documentation here:

/**
* Builds a static mock. Any mocks of this function's declaring class are cancelled before it's mocked
*/
fun mockkStatic(vararg functions: KFunction<*>) =
mockkStatic(*functions.map { it.declaringKotlinFile }.toTypedArray())

@polarene

polarene commented Mar 7, 2023

Copy link
Copy Markdown
Contributor Author

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.

hyochan referenced this pull request in hyochan/react-native-iap Jun 22, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](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` |
[![age](https://badges.renovateapi.com/packages/maven/io.mockk:mockk/1.13.5/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/maven/io.mockk:mockk/1.13.5/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/maven/io.mockk:mockk/1.13.5/compatibility-slim/1.13.4)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/maven/io.mockk:mockk/1.13.5/confidence-slim/1.13.4)](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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;Sandhya2902](https://togithub.com/Sandhya2902) in
[https://github.com/mockk/mockk/pull/1045](https://togithub.com/mockk/mockk/pull/1045)
- Issue [#&#8203;997](https://togithub.com/mockk/mockk/issues/997) -
Simulate garbage collected proxy by
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;SimonMarquis](https://togithub.com/SimonMarquis) in
[https://github.com/mockk/mockk/pull/1047](https://togithub.com/mockk/mockk/pull/1047)

#### New Contributors

- [@&#8203;maeserichar](https://togithub.com/maeserichar) made their
first contribution in
[https://github.com/mockk/mockk/pull/1032](https://togithub.com/mockk/mockk/pull/1032)
- [@&#8203;hfxbse](https://togithub.com/hfxbse) made their first
contribution in
[https://github.com/mockk/mockk/pull/970](https://togithub.com/mockk/mockk/pull/970)
- [@&#8203;ygaller](https://togithub.com/ygaller) made their first
contribution in
[https://github.com/mockk/mockk/pull/1052](https://togithub.com/mockk/mockk/pull/1052)
- [@&#8203;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>
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.

3 participants