GithubHelp home page GithubHelp logo

Comments (11)

johanblumenberg avatar johanblumenberg commented on May 27, 2024 2

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.

LironHazan avatar LironHazan commented on May 27, 2024 1

@pauleustice I started to resolve it using a parser #17 (comment) but I want to try to merge @johanblumenberg PR instead

from ts-mockito.

pauleustice avatar pauleustice commented on May 27, 2024

For reference, previous discussions relating to this issue can be found starting with this comment.

from ts-mockito.

LironHazan avatar LironHazan commented on May 27, 2024

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

pauleustice avatar pauleustice commented on May 27, 2024

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

pauleustice avatar pauleustice commented on May 27, 2024

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

LironHazan avatar LironHazan commented on May 27, 2024

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

LironHazan avatar LironHazan commented on May 27, 2024

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

pauleustice avatar pauleustice commented on May 27, 2024

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.

LironHazan avatar LironHazan commented on May 27, 2024

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

pauleustice avatar pauleustice commented on May 27, 2024

Oh wow, amazing work! Let me know if I can help, I can make some time tomorrow!

from ts-mockito.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.