Skip to content

Commit

Permalink
Merge pull request #10 from polarene/top-level-functions
Browse files Browse the repository at this point in the history
Updated the "Top-level functions" section
  • Loading branch information
NotWoods authored Jan 28, 2023
2 parents 66b85ce + 15d24c4 commit 2be0da3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions content/docs/mocking/extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ weight: 80

## Top-level functions

Kotlin lets you write functions that don't belong to any class or object, called [top-level functions](https://kotlinlang.org/docs/reference/functions.html#function-scope). These calls are translated to static methods in Java, and a special Java class is generated to hold the functions. These top-level functions can be mocked using [`mockkStatic`](./static.md), but you need to figure out the class name of this generated Java class.
Kotlin lets you write functions that don't belong to any class or object, called [top-level functions](https://kotlinlang.org/docs/reference/functions.html#function-scope). These calls are translated to static methods in Java, and a special Java class is generated to hold the functions. These top-level functions can be mocked using [`mockkStatic`](./static.md). You just need to import the function and pass a reference as the argument.

### Finding the class name
```kotlin
import pkg.toplevelFunction

TODO
mockkStatic(::toplevelFunction)
every { toplevelFunction() } returns "top"
```

## Extension functions

Expand Down

0 comments on commit 2be0da3

Please sign in to comment.