Unexpected state API behaviour around unset state
See original GitHub issueThe following code would appear to leave the state unchanged. But after this is matched in runtime. The state will be reset to “nothing” like it had never been set.
_server
.Given( Request.Create().UsingGet().WithPath( new ExactMatcher("/StateUnchanged")))
.InScenario("default")
.WhenStateIs("State2")
.RespondWith( Response.Create().WithBody("State reset to nothing"));
Leading to the following code that is unnecessarily verbose. Particularly with a fluent API. Where the intention seems to underspecify a mock API. And leave the tool to make educated choices.
_server
.Given( Request.Create().UsingGet().WithPath( new ExactMatcher("/StateUnchanged")))
.InScenario("default")
.WhenStateIs("State2")
.WillSetStateTo("State2")
.RespondWith( Response.Create().WithBody("State is still State2"));
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Unexpected Behavior After State Change in React ...
Console.log shows that the state did successfully change. And what is even stranger, is if I run "this.setState({selectedImage:2})" ...
Read more >unexpected behavior with useState. when state is ...
What is the current behavior? Im using a 3rd party jQuery plugin in combination with useState and useEffect hook to bind plugin events...
Read more >5 Most Common useState Mistakes React Developers ...
Find out what the five most common mistakes React developers make with useState and how to avoid them.
Read more >Why is Global State so Evil?
Functions that read or manipulate mutable global state are inherently impure. Code comprehension - code behaviour that depends on a lot of ...
Read more >Updating, deleting, and rearranging non-current entries #9
Updating non-current entries' URLs and states, as opposed to deleting/rearranging them, is related to #7, but I think the lower-level ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@StefH
Awesome!! I like this library, that comment may have spared me from some confusion. It may help someone else. Next time I use this tool, I’ll create an extension method as a shortcut for
.WhenStateIs("x").WillSetStateTo("x")
and I’ll post it here if anyone prefers to use it.Thanks!
@arturohernandez10 Now I understand your question.
Actually, your question looks a lot like this issue : https://github.com/WireMock-Net/WireMock.Net/issues/494
Which was solved by adding an times parameter to the WillSetStateTo method:
IRespondWithAProvider WillSetStateTo(string state, int? times = 1);
In your case, you can set the value for the times to
Int32.MaxValue
.I think this solves your issue. Can you take a look and test ?
Wiki has been updated : The number of times this match should be matched before the state will be changed to the specified one. Default value is 1.