You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a GameController that is an ObservableObject has 2 @Published properties, gameResult and currentTurn, the GameController is also responsible for the gameHeaderTitle String...
I have the following 2 tests in my code, I stripped them down to just what is needed for this issue...
1 test uses the way described for @ObservedObjects and the other uses the way to tests things like @State values...
func testGameBoardTitleIsCorrect_Q1a()throws{
// Given that I have a Game Board
letsut=GameBoardView()letdisplayedText={try sut.inspect().find(viewWithTag:"GameBoardViewTitle").text().string()}XCTAssertEqual(trydisplayedText(),"It's X's turn")
sut.controller.takeTurnAt(0) // X
XCTAssertEqual(trydisplayedText(),"It's O's turn")}func testGameBoardTitleIsCorrect_MoreViewInspector_Q1b()throws{
// Given that I have a Game Board
varsut=GameBoardView()letexp= sut.on(\.didAppear){ view inXCTAssert(try view.actualView().inspect().find(viewWithTag:"GameBoardViewTitle").text().string()=="It's X's turn")try view.actualView().controller.takeTurnAt(0)XCTAssert(try view.actualView().inspect().find(viewWithTag:"GameBoardViewTitle").text().string()=="It's O's turn")}ViewHosting.host(view: sut)wait(for:[exp], timeout: 0.1)}
Those tests pass just fine and the app works, however...
If I remove the @Published from the currentTurn variable, ALL of the test still pass, but the gameHeaderTitle doesn't update the turns when playing the game!
gameHeaderTitle is not @Published, yet when there is a "winner", then it updates properly?!
Did I setup the tests wrong, or is there something wrong when inspecting the View?
I'm a bit confused at the moment, anyone have any ideas?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I created a simple Tic-Tac-Toe game to help learn ViewInspector better...
Repo: Public Repo
I've got a GameController that is an
ObservableObject
has 2@Published
properties,gameResult
andcurrentTurn
, the GameController is also responsible for thegameHeaderTitle
String...In my GameBoardView I have
On to the ViewInspector Question
I have the following 2 tests in my code, I stripped them down to just what is needed for this issue...
1 test uses the way described for
@ObservedObjects
and the other uses the way to tests things like@State
values...Those tests pass just fine and the app works, however...
If I remove the
@Published
from thecurrentTurn
variable, ALL of the test still pass, but thegameHeaderTitle
doesn't update the turns when playing the game!gameHeaderTitle
is not@Published
, yet when there is a "winner", then it updates properly?!Did I setup the tests wrong, or is there something wrong when inspecting the View?
I'm a bit confused at the moment, anyone have any ideas?
Beta Was this translation helpful? Give feedback.
All reactions