ts-mockito icon indicating copy to clipboard operation
ts-mockito copied to clipboard

Issues mocking Auth0 `getProfile is not a function`

Open gavinwilliams opened this issue 7 years ago • 2 comments

I'm trying to mock my Auth0 dependency, however, when I try to mock the class's method with a stub I always get an error stating that the method I want to mock is not a function. See below.

            const authenticationClient = mock(AuthenticationClient)
            const mockedAuthenticationClient = instance(authenticationClient)

            when(authenticationClient.getProfile('efwwef')).thenResolve({
                 ewe: 'wef'
            })

Creating a TypeScript class in the same file with the getProfile method works perfectly fine. I'm not sure what's going on!

gavinwilliams avatar Dec 21 '18 14:12 gavinwilliams

Same problem for me mocking the ManagementClient, I think it's because auth0 add properties to the prototype using Object.defineProperty, where the getter of that property is binding the function when the getter is invoked.

I'm not a ts-mockito contributor, but I don't think this is a problem that can be solved here.

dan-j avatar Feb 14 '19 13:02 dan-j

Hello, We have the same problem mocking Injector on Angular 8. My problem is that the mocked method is abstract.

Maybe it's the same for you. https://github.com/NagRock/ts-mockito/issues/112

deblockt avatar Oct 30 '19 15:10 deblockt