Comments (11)
I fixed it in my fork: johanblumenberg@08979c2
I opened a PR to try to fix it in this repository as well, but it wasn't straightforward. See details in #17.
from ts-mockito.
@pauleustice I started to resolve it using a parser #17 (comment) but I want to try to merge @johanblumenberg PR instead
from ts-mockito.
For reference, previous discussions relating to this issue can be found starting with this comment.
from ts-mockito.
@pauleustice -->
https://github.com/TypeStrong/ts-mockito/tree/15-combinelatest-as-function-issue/test/issue15
Added the tests, fails for same reason and now we can debug,
I'll try to look into it later on today
from ts-mockito.
@LironHazan Cool! I've added some logging into Mock.js
(which Spy.js
extends).
Mocker.prototype.processProperties:
if (descriptor.get) {
console.log('get');
_this.createPropertyStub(name);
_this.createInstancePropertyDescriptorListener(name, descriptor, obj);
_this.createInstanceActionListener(name, obj);
}
else if (typeof descriptor.value === "function") {
console.log('function');
_this.createMethodStub(name);
_this.createInstanceActionListener(name, obj);
}
else {
console.log('neither');
}
When it iterates over the class fields on ExampleService, the following happens:
console.log
observable$
neither
console.log
providerOneObservable$
neither
console.log
combinedProviderObservable$
function
That's why the stub is being added. Now we need to work out what the difference in TS version is, that means the combineLatest
Observable is a function.
EDIT: To clarify, with TS 4.3.5 the log is:
console.log
combinedProviderObservable$
neither
And as such, it does not get stubbed.
from ts-mockito.
@LironHazan I haven't had a chance to do too much more on this, but I've just attempted to isolate the issue further by using ts-mockito outside of Jest. I created a basic TS file, which behaves as expected:
import { Observable } from 'rxjs';
import { BehaviorSubject, combineLatest } from 'rxjs';
import { spy } from 'ts-mockito';
class SimpleClass {
observable$ = new BehaviorSubject('one');
observableTwo$ = new BehaviorSubject('two');
localCombinedObservable$: Observable<string[]> = combineLatest([
this.observable$,
this.observableTwo$,
]);
}
const simple = new SimpleClass();
spy(simple);
simple.localCombinedObservable$.subscribe(([ one, two ]) => {
console.log(one, two);
});
This suggests to me that it isn't Typescript / ts-mockito exclusively, more like Jest, ts-jest or something else... 🤔
from ts-mockito.
@pauleustice Interesting and a different angle than what I thought,
I found that MockableFunctionsFinder recognised the following code as a function
this.localCombinedObservable$ = (0, rxjs_1.combineLatest)([
this.observable$,
this.observableTwo$,
]).pipe((0, operators_1.map)(function (_a) {
var first = _a[0], another = _a[1];
return "".concat(first, "/").concat(another);
}));
This is the transpiled code as string when running version > 4.3.x
And for 4.3.5 its:
this.localCombinedObservable$ = rxjs_1.combineLatest([
this.observable$,
this.observableTwo$,
]).pipe(operators_1.map(function (_a) {
var second = _a[0], third = _a[1];
return second + "/" + third;
}));
I tried to fix the "functionNameRegex" but that didn't work,
But now I don't think that's the issue after seeing your isolated example
from ts-mockito.
@pauleustice btw I tried running with karma instead and still fails for same reason,
TypeError: service.combinedProviderObservable$.subscribe is not a function
from ts-mockito.
Interesting... so it's probably not Jest then! So in your examples above, did MockableFunctionsFinder not show up the this.localCombinedObservable
in 4.3.5? Both of them yield the same result so it's weird that it has issues with the first. I probably won't have time to look at this again today but when I next do, I'll look at that regex too.
from ts-mockito.
@pauleusticeI it seems like my debugger was out of sync!
fixing the regex fixed the issue!
but there are a lot of other tests which fails now so I need to dig into it
from ts-mockito.
Oh wow, amazing work! Let me know if I can help, I can make some time tomorrow!
from ts-mockito.
Related Issues (14)
- Publishing to npm HOT 1
- fix github actions + add action for publishing to npm HOT 9
- Importing this package breaks due to incorrect "main" and "typings" HOT 19
- [META] fork / upstream maintenance discussion HOT 45
- Where are the release notes? HOT 3
- fix auto publish
- How to mock a standalone function? HOT 2
- Instanceof-Operator: (instance(mock(MyClass)) instanceof MyClass) is false.
- Unsafe Argument matchers due to return any
- In-Code Documentation with TSDoc
- Message-parameter for MethodStubVerificator
- Feature request: option to throw instead of returning `null` for non-mocked properties HOT 1
- Feature request: Allow overlapping matchers
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 ts-mockito.