-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7439 from satanTime/issues/6402
fix(MockBuilder): respects global rules as they would be chain calls #6402
- Loading branch information
Showing
4 changed files
with
119 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { HttpClient, HttpClientModule } from '@angular/common/http'; | ||
import { | ||
HttpClientTestingModule, | ||
HttpTestingController, | ||
} from '@angular/common/http/testing'; | ||
import { Injectable, NgModule } from '@angular/core'; | ||
|
||
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
@Injectable() | ||
class TargetService { | ||
constructor(private http: HttpClient) {} | ||
|
||
getConfig() { | ||
return this.http.get('/api/config'); | ||
} | ||
} | ||
|
||
@NgModule({ | ||
imports: [HttpClientModule], | ||
providers: [TargetService], | ||
}) | ||
class TargetModule {} | ||
|
||
// The issue was that MockBuilder didn't apply global rules to mocked declarations. | ||
// @see https://github.com/help-me-mom/ng-mocks/issues/6402 | ||
describe('issue-6402', () => { | ||
describe('MockBuilder:replace', () => { | ||
beforeEach(() => | ||
MockBuilder(TargetService, TargetModule).replace( | ||
HttpClientModule, | ||
HttpClientTestingModule, | ||
), | ||
); | ||
|
||
it('sends /api/config request', () => { | ||
MockRender(TargetService); | ||
const service = ngMocks.get(TargetService); | ||
const controller = ngMocks.get(HttpTestingController); | ||
|
||
service.getConfig().subscribe(); | ||
|
||
const expectation = controller.expectOne('/api/config'); | ||
expectation.flush([]); | ||
controller.verify(); | ||
expect(expectation.request.method).toEqual('GET'); | ||
}); | ||
}); | ||
|
||
describe('ngMocks.globalReplace', () => { | ||
beforeAll(() => | ||
ngMocks.globalReplace( | ||
HttpClientModule, | ||
HttpClientTestingModule, | ||
), | ||
); | ||
beforeEach(() => MockBuilder(TargetService, TargetModule)); | ||
afterAll(() => ngMocks.globalWipe(HttpClientModule)); | ||
|
||
it('sends /api/config request', () => { | ||
MockRender(TargetService); | ||
const service = ngMocks.get(TargetService); | ||
const controller = ngMocks.get(HttpTestingController); | ||
|
||
service.getConfig().subscribe(); | ||
|
||
const expectation = controller.expectOne('/api/config'); | ||
expectation.flush([]); | ||
controller.verify(); | ||
expect(expectation.request.method).toEqual('GET'); | ||
}); | ||
}); | ||
}); |