Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods committed Aug 15, 2023
2 parents de36c94 + 2be0da3 commit 1b7fdb7
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 1b7fdb7

Please sign in to comment.