question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add mock service as a class

See original GitHub issue

Hi! You can add the ability to mock the service as a class. Now you can only mock in the form of an object. Now I can only mock the service in this way:

import {MockService} from "./mocks/mock"

...mock(Service, <Partial<any>>MockService.prototype)

But in this case no static methods are passed.

And I would like the whole class to be mocked.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
getsafcommented, Nov 30, 2019

Thanks for the StackBlitz example… It looks like we uncovered a bug in provideMock. It was not properly “skipping” the built-in mocking when using a Value/Class/Type Provider with provideMock.

I just published a fix (v8.5.2) and updated the official StackBlitz with a new example covering the same scenario you have provided.

With 8.5.2, you should be able to use provideMock without issue:

provideMock({provide: Service, useValue: new MockService()});

Thanks for using Shallow, and thanks for reporting this issue!

Please close this issue if this does resolve your problem.

0reactions
ne3Vubekicommented, Dec 2, 2019

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mockito: How to test my Service with mocking? - Stack Overflow
How do I test a class that has private methods, fields or inner classes? 2231 · How do you assert that a certain...
Read more >
Stubbing and Mocking with Mockito and JUnit - Semaphore CI
Learn how to create true unit tests by mocking all external dependencies in your JUnit classes with the help of Mockito.
Read more >
Injecting Mockito Mocks into Spring Beans - Baeldung
In this tutorial, we'll discuss how to use dependency injection to insert Mockito mocks into Spring Beans for unit testing.
Read more >
Mocking Entities and Services with PHPUnit and Mocks - Drupal
1. Create the class of service: · 2. Create a new container to associate the class with the service name: · 3. Define...
Read more >
MockService - Android Developers
Added in API level 33. Deprecated in API level 33 ... Dismiss Got it. Kotlin |Java. public class MockService extends Object ... A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found