Home > Mobile >  Difference of mock() vs. provide() in ng-mocks
Difference of mock() vs. provide() in ng-mocks

Time:10-24

What is the difference between

https://ng-mocks.sudo.eu/api/MockBuilder#mock

MockBuilder(TargetService, TargetModule)
  .mock(Service2, { trigger: () => 'mock2' })

and

https://ng-mocks.sudo.eu/api/MockBuilder#provide

MockBuilder(TargetService, TargetModule)
  .provide({ provide: Service2, useValue: { trigger: () => 'mock2' }})

CodePudding user response:

.mock will replace the declaration with a mock at its definition, even if it's deeply nested NgModules.

.provide simply adds the declaration to providers of TestBed and doesn't do any additional replacements in imported NgModules.

  • Related