Comments (3)
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.
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.
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)
- Confusing failure with nested mocks HOT 6
- Calling `when` consecutively doesn't stub mocks HOT 2
- Not compatible with freezed 2.4.2 HOT 5
- mocktail could offer string diffs on call failures? HOT 2
- mockNetworkImages should provide a way to test the errorBuilder from Image.network
- Should when() calls have a better error message for not having a following thenAnswer/thenReturn call?
- [Question] Verify constructor HOT 2
- Matcher is not working properly is specific case due to Object? HOT 2
- How to Mock multiple calls? HOT 1
- How to Mock a State? HOT 1
- while giving header or body to http. mock type 'Null' is not a subtype of type 'Future<Response>' this error coming HOT 3
- Repository.updateItem() Function Throws Null Subtype Exception in Bloc Test Event HOT 1
- captureAny list order differs in release mode HOT 3
- type 'Null' is not a subtype of type 'Entity'
- Mock or skip void method and global method HOT 1
- Mock with default stub implementation feature HOT 3
- Verify of objects passed in isolates don't work HOT 1
- Used on a non-mocktail object HOT 1
- mocktail_image_network: HTTP request failed, statusCode: 400 under certain conditions HOT 1
- mocktail gives confusing errors when there is an incomplete mock HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mocktail.