Handle primitive values
See original GitHub issueI see some benefit to being able for mock<...>()
to also mock primitive values.
For example:
interface Baz {
quux: boolean
}
interface Foo {
bar: string
baz: Baz
}
const foo = mock<Foo>()
// modifidy mock return value for quux
foo.baz.quux.mockReturnValueOnce(false)
Refer to #3 and https://github.com/reergymerej/super-mockable-non-functions/blob/master/src/index.js
Thoughts?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Primitive Data Types (The Java™ Tutorials > Learning the ...
Primitive Data Types ... The Java programming language is statically-typed, which means that all variables must first be declared before they can be...
Read more >Primitive vs Reference Data Types in JavaScript
Now that we've seen how easy it is to handle primitive data types, let's see how similarly reference data types work.
Read more >Java: Understanding Primitive Types and Wrapper Objects
Java defines eight primitive data types: byte, short, int, long, float, double, boolean and char. All other variables in java are object ...
Read more >Java Primitives versus Objects - Baeldung
Java has a two-fold type system consisting of primitives such as int, boolean and reference types such as Integer, Boolean. Every primitive ......
Read more >Data Types in Java | Primitive and Non-Primitive Data Types
Primitive Data Types: A primitive data type is pre-defined by the programming language. The size and type of variable values are specified, ...
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
My current workaround is this:
If you do not need spying capabilities and just want
quux
to have a fixed value, you can doBut this seems to be more complicated then necessary. It should be possible to write
And actually, this does work (even with mockDeep), but not for falsy values like in the example. I believe this is due to line 86 in Mock.ts, which reads
if (!obj[property]) {
but should rather beif (!(property in obj)) {
I tested this solution and it works great. Why is this fix not committed yet?