Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
jasmine-auto-spies
Advanced tools
Create automatic spies from classes in jasmine tests for promises and observables
Create automatic spies from classes in jasmine tests. If you're using TypeScript it'll also create auto spies for Promise or Observable returning methods and provide type completion.
Keep you tests Dry - no more repeated spy setup code, no need for separate spy files
Type completion for both the original Class and the spy methods
Automatic return type detection by using a simple decorator
npm install -D jasmine-auto-spies
In your tsconfig.json
set these 2 flags -
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
}
}
Let's say you have a class -
class MyService{
getName(): string{
return 'Bonnie';
}
}
This is how you create an automatic spy for it -
import { Spy, createSpyFromClass } from 'jasmine-auto-spies';
let myServiceSpy: Spy<MyService>;
beforeEach( ()=> {
myServiceSpy = createSpyFromClass( MyService );
});
it(){
myServiceSpy.getName.and.returnValue('Fake Name');
... (the rest of the test) ...
}
Promise
returning methodFirst, annotate the method with @AsyncSpyable
-
import { AsyncSpyable } from 'jasmine-auto-spies';
export class MyService{
@AsyncSpyable() // <-- MUST ADD THIS
getItems(): Promise<any> {
return Promise.resolve( itemsList );
}
}
Now you can use the resolveWith
or rejectWith
methods -
import { Spy, createSpyFromClass } from 'jasmine-auto-spies';
let myServiceSpy: Spy<MyService>;
beforeEach( ()=> {
myServiceSpy = createSpyFromClass( MyService )
});
it(){
myServiceSpy.getItems.and.resolveWith( fakeItemsList );
// OR
myServiceSpy.getItems.and.rejectWith( fakeError );
}
Observable
returning methodFirst, annotate your Observable returning method with @AsyncSpyable
-
import { AsyncSpyable } from 'jasmine-auto-spies';
export class MyService{
@AsyncSpyable() // <-- MUST ADD THIS
getProducts(): Observable<any> {
return Observable.of( productsList );
}
}
Now you can use the nextWith
method -
import { Spy, createSpyFromClass } from 'jasmine-auto-spies';
let myServiceSpy: Spy<MyService>;
beforeEach( ()=> {
myServiceSpy = createSpyFromClass( MyService )
});
it(){
myServiceSpy.getProducts.and.nextWith( fakeProductsList);
}
FAQs
Create automatic spies from classes in jasmine tests, also for promises and observables
The npm package jasmine-auto-spies receives a total of 14,427 weekly downloads. As such, jasmine-auto-spies popularity was classified as popular.
We found that jasmine-auto-spies 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
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.