
-- AuthContext 를 세 층으로 테스트한다
-- 1 저장소: Storage.prototype.getItem 을 spy
getItem "auth_token" = Just "test_token"
getItem _ = Nothing
-- 2 Provider: token 을 보여 주고 login·logout 을 누르는 테스트 컴포넌트로 상태 변화를 본다
testComponent = do
Auth { token, login, logout } <- useAuth
pure [p "token" (fromMaybe "null" token), button (login "test_token"), button logout]
-- 3 훅: Provider 밖이면 에러, 안이면 token 이 null 로 시작
useAuth :: Maybe AuthContext -> Either Error Auth
useAuth Nothing = Left (Error "AuthProvider 밖")
useAuth (Just ctx) = Right (auth ctx)
-- renderHook useAuth → throws
-- renderHook useAuth { wrapper = AuthProvider } → token == null