Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Mocks: Crashes when touching array of object (Reproduced in main branch) #2588

Closed
konomae opened this issue Oct 18, 2022 · 3 comments · Fixed by #2591
Closed

Test Mocks: Crashes when touching array of object (Reproduced in main branch) #2588

konomae opened this issue Oct 18, 2022 · 3 comments · Fixed by #2591
Assignees
Labels
bug Generally incorrect behavior

Comments

@konomae
Copy link

konomae commented Oct 18, 2022

Bug report

Test Mocks: Crashes when touching array of object (Reproduced in main branch)

Versions

  • apollo-ios SDK version: main (1045d8c)
  • Xcode version: 14.0
  • Swift version: 5.7
  • Package manager: 5.7

Steps to reproduce

1. Generate schema and test mocks

schema

type Dog {
    id: ID!
}

type Query {
    dogs: [Dog!]!
}

query

query Dogs {
    dogs {
        id
    }
}

2. Run tests

class DemoTests: XCTestCase {
    func test_crash() {
        let mock = Mock<Query>(dogs: [])
        DogsQuery.Data.from(mock).dogs // ok
        
        mock.dogs = [Mock(id: "dog-1")]
        // Thread 1: Fatal error: Dog expected data for entity.
        DogsQuery.Data.from(mock).dogs // crash
    }
}

screenshot

Further details

  • Released version 1.0.1 does not have this problem
@AnthonyMDev
Copy link
Contributor

Oooof. This must have regressed when I fixed the other crash. I thought we have a test for this, but I will check again and fix this before the 1.0.2 release! Thanks for the report.

Aside from this issue, I'd love to hear feedback on how your experience with Test Mocks has been so far.

@konomae
Copy link
Author

konomae commented Oct 19, 2022

Thank you for the fix!
I tried test-mock-list-fix branch and this crash was solved. 🎉

Aside from this issue, I'd love to hear feedback on how your experience with Test Mocks has been so far.

So far, it is helpful for migration from 0.x to 1.0. Since it only requires a small rewrite of existing code. 👍

-let data = MyQuery.Data(
+let data = MyQuery.Data.from(Mock(
     dogs = .init(id: "id")
     // more properties
-)
+))

@AnthonyMDev
Copy link
Contributor

Glad to hear! Fix in the the main branch now and will be in the 1.0.2 release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants