Skip to content

How to mock a property #525

Answered by MikeSchulze
tetious asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, The get/set functional syntax is actual not supported to mock.

For your example

class_name Foo

var _bar: Bar

var prop: int:
    get: return _bar.something.else

There are two options to mock it.
a) mock class Bar and set the _bar value with the mocked instance in your class Foo
b) implement a custom getter function and mock this function
like you did in your example

func _get_prop() -> int:
  return _bar.something.else

I would prefer option a)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tetious
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested clarified
2 participants