I don't understand a test failure #3392
Unanswered
easiwriter
asked this question in
Q&A
Replies: 2 comments 3 replies
-
Hi @easiwriter, you should provide the full compiling project in order for someone to help. Providing only a few files makes it difficult for someone to understand how everything connects together. And if you can't provide the project, then please reproduce the problem in a minimal project and share that. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Hi Brandon
Thanks for this, which confirms my suspicion about SwiftData. I will investigate ways out of the impasse. When do you think TCA will handle this, if ever?
… On 17 Sep 2024, at 14:18, Brandon Williams ***@***.***> wrote:
Hi @easiwriter <https://github.com/easiwriter>, this assertion is failing:
await store.send(.addButtonTapped) {
$0.addProject?.project = project
$0.addProject?.projectModel = project.fromProject()
}
…because addProject is nil, and so assigning through addProject?. is just a no-op. The test failure message tries to explain this:
🛑 Issue recorded: A state change does not match expectation: …
ProjectsList.State(
_context: ModelContext(…),
− _addProject: nil,
+ _addProject: ProjectForm.State(
+ …
+ )
(Expected: −, Actual: +)
This message is saying that you asserted that addProject was nil, but in reality it was non-nil. Is there something that could be improved with this messaging?
To fix need to assign all of addProject in this assertion:
await store.send(.addButtonTapped) {
$0.addProject = …
}
And then this assertion is failing:
await store.send(.saveProjectButtonTapped) {
$0.projects = [project]
$0.addProject = nil
}
…because projectModels changed but you didn't assert on those state changes. Again the test failure message tries to explain this:
🛑 Issue recorded: A state change does not match expectation: …
ProjectsList.State(
_context: ModelContext(…),
_addProject: nil,
_projectModels: #1 IdentifiedArray(
+ ProjectModel(
+ _id: ProjectModel._SwiftDataNoType(),
+ _name: ProjectModel._SwiftDataNoType(),
+ _type: ProjectModel._SwiftDataNoType(),
+ _listMarkers: ProjectModel._SwiftDataNoType(),
+ _paperName: ProjectModel._SwiftDataNoType(),
+ _timeStamp: nil,
+ _pageSetup: nil,
+ _styleSheet: nil,
+ _folders: nil,
+ _textFiles: nil
+ )
),
_projects: #2 […],
_templates: #3 […]
)
(Expected: −, Actual: +)
I will also say that unfortunately Swift Data does not immediately play nicely with TCA's testing tools. Our tools are mostly built on the properties of value types because they can be copied before and after an action is sent so that we can compare what changed. And unfortunately Swift Data is mostly built on reference types, which are much more difficult (or often impossible) to unit test. So in general you are going to have a very difficult time testing Swift Data in a TCA app.
—
Reply to this email directly, view it on GitHub <#3392 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEUXIA7I2T4GMH5ADRKSRHDZXAT4DAVCNFSM6AAAAABOK6T2V6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTANRXGA3DMMY>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am struggling to get a test to work. It is modelled after a similar test in SyncUps. The test that fails is testAddProjectButtonTapped at line 22. I have provided the relevant sources in the archive. It also contains the failed state change in Results.rtf.
What I thought happens is that the project is assigned to the ProjectForm.project and that this should work. What appears to happen is the test doesn't like the project for some reason. My suspicion is that it has something to do with SwiftData because everything works if I take SwiftData out of the equation and use structs without the relationships. Maybe it is the way SwiftData stores model data is upsetting the test framework?
The app itself functions as expected.
Archive.zip
Beta Was this translation helpful? Give feedback.
All reactions