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

[ERROR: Bad state] Mocking response with when() #26

Closed
cocacrave opened this issue Feb 28, 2020 · 2 comments
Closed

[ERROR: Bad state] Mocking response with when() #26

cocacrave opened this issue Feb 28, 2020 · 2 comments

Comments

@cocacrave
Copy link

Trying to mock when().then() but I get an error:
ERROR: Bad state: Mock method was not called within when(). Was a real method called?

test(
      'should return user document',
      () async {
        when(mockService.collection(any).document(any)).thenAnswer(
          (_) => tUserDoc,
        );
        // expect
        // verify
      },
@suztomo
Copy link
Collaborator

suztomo commented Mar 1, 2020

(I'm not author of this library) This library is becoming more "fake" than "mock". To prepare database that contain some data, you need to populate it.

mockFirestoreInstance.collection("users").add({"name": "suztomo"});

If you just need a mock, using mockito (without cloud_firestore_mocks) should suffice.

@atn832 In document, you may want to clarify which parts are "fake" and what are "mock". (I believe this library is a "fake", and fake is suitable for my usage)
Difference between fake and mock: https://blog.pragmatists.com/test-doubles-fakes-mocks-and-stubs-1a7491dfa3da

This was referenced Mar 6, 2020
@atn832
Copy link
Owner

atn832 commented Mar 6, 2020

You're right, calling the library mocks is a misnomer. It was true initially since everything extended Mock and implementation was minimal. I've filed #33 and #34. I'll see if #34 is doable.

Closing this since the workaround is to populate the fake db like @suztomo mentioned.

@atn832 atn832 closed this as completed Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants