Explicitly allowing default property behaviour on a strict Fake
See original GitHub issueThe default read/write behaviour of a faked property is very useful, however, it seems that there is no way to allow it on a strict Fake by explicitly calling any available configuration method.
A solution could be adding a generalization of the DoesNothing
method (UsesDefaultBehaviour
?), so allowed calls could be configured like this:
var i = A.Fake<IInterface>(o => o.Strict());
A.CallTo(() => i.Property)
.UsesDefaultBehaviour();
A.CallToSet(() => i.Property)
.UsesDefaultBehaviour();
It would be even more convenient if a dedicated method wrapping both getter and setter was also added:
var i = A.Fake<IInterface>(o => o.Strict());
A.CallToProperty(() => i.Property)
.UsesDefaultBehaviour();
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
How to properly use default values for properties on ...
no, you have to explicitly allow undefined to be passed as well. In strict mode, boolean and boolean | undefined are different types...
Read more >Specifying a Fake's Behavior - FakeItEasy Succinctly Ebook
Simply put, specifying Strict on any created fakes forces you to configure them. Any calls to unconfigured members throw an exception. Let's ...
Read more >Default fake behavior
Fake objects come with useful default behavior as soon as they are created. ... Methods and properties can only be faked if they...
Read more >Apache Tomcat 8 Configuration Reference (8.5.92) - System ...
Introduction. The following sections list the system properties that may be set to modify the default Tomcat behaviour. Property replacements ...
Read more >Binding to Data Services with Spring Boot in Cloud Foundry
Use the Spring Boot default autoconfiguration and declare the cloud bindings using application.properties (or in YAML). To take full advantage ...
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 FreeTop 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
Top GitHub Comments
@PiotrKlecha, I don’t really understand how you wouldn’t know when to change a method’s behaviour, since you would know if you are making a call to change the behaviour between test phases.
It’s a bit of an abuse, but worst case, you could check a flag inside a
WhenArgumentsMatch
matcher (https://fakeiteasy.readthedocs.io/en/stable/argument-constraints/#overriding-argument-matchers)And then flip the flag when you want the behaviour to revert.
Regardless, I think this still seems like a very very edge case, and making use of the existing tools is a better solution than adding such a niche operation to the main library.
@blairconrad, I meant that a test using a limited call specifier like
Once
is more likely to fail in an unexpected way if the production code changes and calls the configured method a different number of times. Or it may not detect that additional calls are not properly caught, because they will not throw exceptions at all.The suggested ‘abuse’ actually seems to be quite reasonable. Too bad it won’t help with strict Fake property configuration 😞