pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
12.22k stars 1.42k forks source link

Tutorial won't compile: Meet The Composable Architecture - Testing your Feature, Testing Effects, Step 7 has an error #2268

Closed awolf-foreflight closed 1 year ago

awolf-foreflight commented 1 year ago

Description

The tutorial has an error on line 14. This won't compile for me with Xcode 14.3.1 despite the store defined on line 7 being an instance of TestStore.

You can see the autocompleted doesn't provide the expected receive method. When I paste it in the code from the tutorial the test won't compile

image

This is a screen grab of the tutorial:

image

Checklist

Expected behavior

Copying and pasting code from a tutorial should compile

Actual behavior

Multiple compiler errors

This screen grab shows if you simply instantiate a test store with TestStore() then autocomplete works and the test compiles

image

But using the store constant doesn't work. 🤷‍♂️

The root cause appears to be that the tutorial doesn't tell us to add the following line to the CounterFeature.swift file.

extension CounterFeature.Action: Equatable {}

this fixes the problem

I got lucky and got an error about Action needing to be equatable and remembered the trick the tutorial required to make State equatable.

But this is a frustrating experience and difficult to resolve.

Steps to reproduce

Copy paste tutorial example code, try to compile, observe compiler error

The Composable Architecture version information

0.55.0

Destination operating system

ios 16.3

Xcode version information

14.3.1

Swift Compiler version information

awolf@Lins-iPhone-5s ios % xcrun swiftc --version
swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
mbrandonw commented 1 year ago

Hi @awolf-foreflight, a few steps before the step you highlight it was mentioned that the actions need to be made Equatable:

https://github.com/pointfreeco/swift-composable-architecture/blob/af16494b9e6ccd306605aa328f5deea3d75cd33a/Sources/ComposableArchitecture/Documentation.docc/Tutorials/MeetTheComposableArchitecture/01-Essentials/03-TestingYourFeatures/01-03-TestingYourFeature.tutorial#L157-L158

Maybe this could be improved, but it's not really an issue with the library so I am going to convert this to a discussion where we can further discuss ways to improve this.