Giter Club home page Giter Club logo

Comments (3)

Albert221 avatar Albert221 commented on May 18, 2024

Hi! I just stumbled upon the:

Bad state: A test tried to use `any` or `captureAny` on a parameter of type `UserState`, but
registerFallbackValue was not previously called to register a fallback value for `UserState`

To fix, do:

\```
void main() {
  setUpAll(() {
    registerFallbackValue<UserState>(UserState());
  });
}
\```

If you cannot easily create an instance of UserState, consider defining a `Fake`:

\```
class UserStateFake extends Fake implements UserState {}

void main() {
  setUpAll(() {
    registerFallbackValue<UserState>(UserStateFake());
  });
}
\```

I thought that my use case and/or thought process will help you improve the error message.

I am using both mockito and bloc_test in my tests, but I have import on mocktail (aliased mocktail) in my test file where I need mocked cubit. I have this code:

BlocProvider<UserCubit>(create: (_) {
  final mock = MockUserCubit();
  mocktail
      .when(() => mock.state)
      .thenReturn(UserState.loadSuccess(user0));
  return mock;
}),

This is what I'd do in Mockito. But this throws the error above. I'm not sure why does this happen nor why do I need to call this registerFallbackValue.

from mocktail.

felangel avatar felangel commented on May 18, 2024

Hi @Albert221 👋
Sorry for the inconvenience! This is currently working as expected as described in #42 (comment). Let me know if that helps 👍

from mocktail.

felangel avatar felangel commented on May 18, 2024

Closing this because this is working as expected. In the above example, when is evaluated before setUpAll which means that registerFallbackValue hasn't been called yet. In general, I don't recommend using when outside of setUp or test because it will likely result in unexpected behavior since that code will be evaluated prior to any test setup or execution.

from mocktail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.