New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jasmine-auto-spies

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jasmine-auto-spies - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

2

package.json
{
"name": "jasmine-auto-spies",
"version": "4.0.0",
"version": "4.1.0",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

@@ -40,3 +40,3 @@ # jasmine-auto-spies

✅ **Automatic return type detection** by using a simple decorator
✅ **Automatic return type detection** by using a conditional types

@@ -49,5 +49,31 @@ ## Installation

### `my-component.js`
```js
// my-spec.js
export class MyComponent {
constructor(myService) {
this.myService = myService;
}
init() {
this.compData = this.myService.getData();
}
}
```
### `my-service.js`
```js
export class MyService{
getData{
return [
{ ...someRealData... }
]
}
}
```
### `my-spec.js`
```js
import { createSpyFromClass } from 'jasmine-auto-spies';

@@ -57,14 +83,15 @@ import { MyService } from './my-service';

describe('MyComponent', ()=>{
describe('MyComponent', () => {
let myServiceSpy;
let componentUnderTest;
beforeEach(()=>{
myServiceSpy = createSpyFromClass(MyService);
beforeEach(() => {
myServiceSpy = createSpyFromClass(MyService); // <- THIS IS THE IMPORTANT LINE
componentUnderTest = new MyComponent(myServiceSpy);
});
it('should get data on init', ()=>{
const fakeData = [{fake: 'data'}];
it('should fetch data on init', () => {
const fakeData = [{ fake: 'data' }];
myServiceSpy.getData.and.returnWith(fakeData);

@@ -77,28 +104,3 @@

});
});
// my-component.js
export class MyComponent{
constructor(myService){
this.myService = myService;
}
init(){
this.compData = this.myService.getData();
}
}
// my-service.js
export class MyService{
getData{
return [
{ ...someRealData... }
]
}
}
```

@@ -108,15 +110,2 @@

### TypeScript Setup
Set these 2 properties in your `tsconfig.json` -
```json
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
```
### 1. Spying on regular sync methods

@@ -130,3 +119,3 @@

let myServiceSpy: Spy<MyService>;
let myServiceSpy: Spy<MyService>; // <- THIS IS THE IMPORTANT LINE

@@ -137,3 +126,3 @@ beforeEach( ()=> {

it('should Do something' ()=> {
it('should do something' ()=> {
myServiceSpy.getName.and.returnValue('Fake Name');

@@ -174,3 +163,3 @@

### 3. Spy on a `Observable` returning method
### 3. Spy on an `Observable` returning method

@@ -177,0 +166,0 @@ Use the `nextWith` or `throwWith` and other methods -

@@ -12,8 +12,8 @@ export interface SpyFunctionReturnValueContainer {

returnValue?: (value: any) => MockTransformer;
resolveWith?: (value: any) => MockTransformer;
rejectWith?: (value: any) => MockTransformer;
nextWith?(value: any): MockTransformer;
nextOneTimeWith?(value: any): MockTransformer;
resolveWith?: (value?: any) => MockTransformer;
rejectWith?: (value?: any) => MockTransformer;
nextWith?(value?: any): MockTransformer;
nextOneTimeWith?(value?: any): MockTransformer;
throwWith?(value: any): MockTransformer;
complete?(): MockTransformer;
}

@@ -9,8 +9,8 @@ /// <reference types="jasmine" />

export interface PromiseSpyMethod<T> {
resolveWith(value: T): MockTransformer;
rejectWith(value: any): MockTransformer;
resolveWith(value?: T): MockTransformer;
rejectWith(value?: any): MockTransformer;
}
export interface ObservableSpyMethod<T> {
nextWith(value: T): MockTransformer;
nextOneTimeWith(value: T): MockTransformer;
nextWith(value?: T): MockTransformer;
nextOneTimeWith(value?: T): MockTransformer;
throwWith(value: any): MockTransformer;

@@ -17,0 +17,0 @@ complete(): MockTransformer;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc