Installations
npm install ngx-http-test
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.3.0
NPM Version
5.4.0
Score
64
Supply Chain
91.4
Quality
74.9
Maintenance
50
Vulnerability
97.3
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (84.98%)
JavaScript (15.02%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
blacksonic
Download Statistics
Total Downloads
29,484
Last Day
1
Last Week
2
Last Month
31
Last Year
236
GitHub Statistics
17 Stars
37 Commits
3 Forks
4 Watching
1 Branches
4 Contributors
Bundle Size
4.70 kB
Minified
1.38 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.3.2
Package Id
ngx-http-test@1.3.2
Size
7.82 kB
NPM Version
5.4.0
Node Version
8.3.0
Total Downloads
Cumulative downloads
Total Downloads
29,484
Last day
-75%
1
Compared to previous day
Last week
-85.7%
2
Compared to previous week
Last month
342.9%
31
Compared to previous month
Last year
-32.6%
236
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
2
Dev Dependencies
22
ngx-http-test
Makes testing Http calls in Angular 2 as easy as were in AngularJS.
Installation
1npm install ngx-http-test --save-dev
Usage
1// First add it as a provider 2beforeEach(() => { 3 TestBed.configureTestingModule({ 4 providers: [ 5 ... 6 FakeBackend.getProviders() 7 ] 8 }); 9}); 10 11// Get the instance of it 12beforeEach(inject([..., FakeBackend], (..., fakeBackend: FakeBackend) => { 13 backend = fakeBackend; 14})); 15 16// Use it in a test case 17it('should call fake endpoint', (done) => { 18 backend.expectGET('users/blacksonic').respond({ username: 'blacksonic' }); 19 20 subject.getProfile('blacksonic').subscribe((response) => { 21 expect(response).toEqual({ username: 'blacksonic' }); 22 done(); 23 }); 24})
It is possible to specify every detail of the response.
1// can be object, it will be json stringified if not a string 2let responseBody = { username: 'blacksonic' }; 3let responseStatus = 200; 4let responseHeaders = { 'Content-Type': 'application/json' }; 5 6backend 7 .expectGET('users/blacksonic') 8 .respond(responseBody, responseStatus, responseHeaders);
It is not necessary to give the response, in that case the backend will respond with 200 empty response.
Also the expected url can be given as a regular expression instead of a string.
For requests outside of GET the request body can be also specified.
1backend.expectPost( 2 'usernamepassword/login', // url 3 { username: 'blacksonic', password: 'secret' }, // payload 4 { 'Content-Type': 'application/json' } // headers 5).respond(responseForm);
Convenience methods available for different kind of requests:
expectGet
, expectPost
, expectDelete
, expectPut
, expectPatch
, expectHead
, expectOptions
.
After the tests run it is possible to check for outstanding connections or expectations that are not addressed.
1afterEach(() => { 2 backend.verifyNoPendingRequests(); 3 backend.verifyNoPendingExpectations(); 4});
By default expectations get verified instantly, but this can be switched off and do the verification by hand.
1it('should call fake endpoint', (done) => { 2 backend.setAutoRespond(false); 3 backend.expectGET('users/blacksonic').respond({ username: 'blacksonic' }); 4 5 subject.getProfile('blacksonic').subscribe((response) => { 6 expect(response).toEqual({ username: 'blacksonic' }); 7 done(); 8 }); 9 10 backend.flush(); 11})
The flush
method resolves all pending connections. It can also be resolved one by one with the flushNext
method.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 3/27 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
2.7
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to ngx-http-test
@teamteanpm2024/assumenda-accusantium-consequatur
> Ngx Packages by manoj10101996
ngx-grpc-interceptor
Angular is a framework and offers an HTTP client service that we can use straight away. We use it instead of using `fetch` for example because it lets us not only test our code but also have super useful features with dependency injection like providing