Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
angular2-http-testing
Advanced tools
Makes testing Http calls as easy as were with AngularJS.
npm install angular2-http-testing --save-dev
// First add it as a provider
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
...
FakeBackend.getProviders()
]
});
});
// Get the instance of it
beforeEach(inject([..., FakeBackend], (..., fakeBackend: FakeBackend) => {
backend = fakeBackend;
}));
// Use it in a test case
it('should call fake endpoint', (done) => {
backend.expectGET('users/blacksonic').respond({ username: 'blacksonic' });
subject.getProfile('blacksonic').subscribe((response) => {
expect(response).toEqual({ username: 'blacksonic' });
done();
});
})
It is possible to specify every detail of the response.
// can be object, it will be json stringified if not a string
let responseBody = { username: 'blacksonic' };
let responseStatus = 200;
let responseHeaders = { 'Content-Type': 'application/json' };
backend
.expectGET('users/blacksonic')
.respond(responseBody, responseStatus, responseHeaders);
For requests outside of GET the request body can be also specified.
backend.expectPost(
'usernamepassword/login', // url
{ username: 'blacksonic', password: 'secret' }, // payload
{ 'Content-Type': 'application/json' } // headers
).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.
afterEach(() => {
backend.verifyNoPendingRequests();
backend.verifyNoPendingExpectations();
});
FAQs
Angular 2 Http testing helper
The npm package angular2-http-testing receives a total of 7 weekly downloads. As such, angular2-http-testing popularity was classified as not popular.
We found that angular2-http-testing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.