question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected state API behaviour around unset state

See original GitHub issue

The 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:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
arturohernandez10commented, Sep 3, 2020

@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!

0reactions
StefHcommented, Aug 30, 2020

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found