Huge News!Announcing our $40M Series B led by Abstract Ventures.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 3.1.0 to 3.2.0

src/error-handling.d.ts

4

package.json
{
"name": "jasmine-auto-spies",
"version": "3.1.0",
"version": "3.2.0",
"repository": {

@@ -53,2 +53,3 @@ "type": "git",

"@commitlint/config-conventional": "7.0.1",
"@types/deep-equal": "1.0.1",
"@types/jasmine": "^2.5.53",

@@ -90,2 +91,3 @@ "@types/jasmine-given": "^2.6.0",

"dependencies": {
"deep-equal": "1.0.1",
"window-or-global": "1.0.1"

@@ -92,0 +94,0 @@ },

@@ -6,2 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var deep_equal_1 = __importDefault(require("deep-equal"));
var error_handling_1 = require("./error-handling");
var rxjs_1 = require("rxjs");

@@ -16,6 +18,7 @@ var window_or_global_1 = __importDefault(require("window-or-global"));

var returnTypeClass = Reflect.getMetadata('design:returntype', proto, methodName);
var spyMethod = createSpyFunction(methodName);
if ((providedPromiseMethodNames &&
providedPromiseMethodNames.indexOf(methodName) !== -1) ||
returnTypeClass === Promise) {
autoSpy[methodName] = createPromiseSpyFunction(methodName);
autoSpy[methodName] = createPromiseSpyFunction(spyMethod);
}

@@ -25,6 +28,6 @@ else if ((providedObservableMethodNames &&

returnTypeClass === rxjs_1.Observable) {
autoSpy[methodName] = createObservableSpyFunction(methodName);
autoSpy[methodName] = createObservableSpyFunction(spyMethod);
}
else {
autoSpy[methodName] = jasmine.createSpy(methodName);
autoSpy[methodName] = spyMethod;
}

@@ -35,4 +38,3 @@ });

exports.createSpyFromClass = createSpyFromClass;
function createObservableSpyFunction(name) {
var spyFunction = jasmine.createSpy(name);
function createObservableSpyFunction(spyFunction) {
var subject = new rxjs_1.ReplaySubject(1);

@@ -43,2 +45,6 @@ spyFunction.and.returnValue(subject);

};
spyFunction.and.nextOneTimeWith = function nextOneTimeWith(value) {
subject.next(value);
subject.complete();
};
spyFunction.and.throwWith = function throwWith(value) {

@@ -50,6 +56,66 @@ subject.error(value);

};
spyFunction.calledWith = function () {
var calledWithArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
calledWithArgs[_i] = arguments[_i];
}
return {
nextWith: function (value) {
spyFunction.and.callFake(function () {
var actualArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
actualArgs[_i] = arguments[_i];
}
if (!deep_equal_1.default(calledWithArgs, actualArgs)) {
error_handling_1.throwArgumentsError(calledWithArgs, actualArgs);
}
subject.next(value);
return subject;
});
},
nextOneTimeWith: function (value) {
spyFunction.and.callFake(function () {
var actualArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
actualArgs[_i] = arguments[_i];
}
if (!deep_equal_1.default(calledWithArgs, actualArgs)) {
error_handling_1.throwArgumentsError(calledWithArgs, actualArgs);
}
subject.next(value);
subject.complete();
return subject;
});
},
throwWith: function (value) {
spyFunction.and.callFake(function () {
var actualArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
actualArgs[_i] = arguments[_i];
}
if (!deep_equal_1.default(calledWithArgs, actualArgs)) {
error_handling_1.throwArgumentsError(calledWithArgs, actualArgs);
}
subject.error(value);
return subject;
});
},
complete: function () {
spyFunction.and.callFake(function () {
var actualArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
actualArgs[_i] = arguments[_i];
}
if (!deep_equal_1.default(calledWithArgs, actualArgs)) {
error_handling_1.throwArgumentsError(calledWithArgs, actualArgs);
}
subject.complete();
return subject;
});
}
};
};
return spyFunction;
}
function createPromiseSpyFunction(name) {
var spyFunction = jasmine.createSpy(name);
function createPromiseSpyFunction(spyFunction) {
spyFunction.and.returnValue(new Promise(function (resolveWith, rejectWith) {

@@ -59,4 +125,60 @@ spyFunction.and.resolveWith = resolveWith;

}));
spyFunction.calledWith = function () {
var calledWithArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
calledWithArgs[_i] = arguments[_i];
}
return {
resolveWith: function (value) {
spyFunction.and.callFake(function () {
var actualArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
actualArgs[_i] = arguments[_i];
}
if (!deep_equal_1.default(calledWithArgs, actualArgs)) {
error_handling_1.throwArgumentsError(calledWithArgs, actualArgs);
}
return Promise.resolve(value);
});
},
rejectWith: function (value) {
spyFunction.and.callFake(function () {
var actualArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
actualArgs[_i] = arguments[_i];
}
if (!deep_equal_1.default(calledWithArgs, actualArgs)) {
error_handling_1.throwArgumentsError(calledWithArgs, actualArgs);
}
return Promise.reject(value);
});
}
};
};
return spyFunction;
}
function createSpyFunction(name) {
var spyFunction = jasmine.createSpy(name);
spyFunction.calledWith = function () {
var calledWithArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
calledWithArgs[_i] = arguments[_i];
}
return {
returnValue: function (value) {
spyFunction.and.callFake(function () {
var actualArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
actualArgs[_i] = arguments[_i];
}
if (!deep_equal_1.default(calledWithArgs, actualArgs)) {
error_handling_1.throwArgumentsError(calledWithArgs, actualArgs);
}
return value;
});
}
};
};
return spyFunction;
}
function getAllMethodNames(obj) {

@@ -63,0 +185,0 @@ var methods = [];

@@ -7,19 +7,27 @@ /// <reference types="jasmine" />

export declare type AddSpyTypes<T> = T extends (...args: any[]) => any ? AddSpyByReturnTypes<T> : T;
export interface PromiseSpy<T> {
export interface PromiseSpyMethod<T> {
resolveWith(value: T): void;
rejectWith(value: any): void;
}
export interface ObservableSpy<T> {
export interface ObservableSpyMethod<T> {
nextWith(value: T): void;
nextOneTimeWith(value: T): void;
throwWith(value: any): void;
complete(): void;
}
export declare type AddSpyOnFunction<T extends (...args: any[]) => any> = T & jasmine.Spy;
export interface SpyMethod {
calledWith(...args: any[]): {
returnValue: (value: any) => void;
};
}
export declare type AddSpyOnFunction<T extends (...args: any[]) => any> = T & SpyMethod & jasmine.Spy;
export declare type AddSpyOnPromise<T extends Promise<any>> = {
and: PromiseSpy<Unpacked<T>>;
and: PromiseSpyMethod<Unpacked<T>>;
calledWith(...args: any[]): PromiseSpyMethod<T>;
} & jasmine.Spy;
export declare type AddSpyOnObservable<T extends Observable<any>> = {
and: ObservableSpy<Unpacked<T>>;
and: ObservableSpyMethod<Unpacked<T>>;
calledWith(...args: any[]): ObservableSpyMethod<T>;
} & jasmine.Spy;
export declare type AddSpyByReturnTypes<TF extends (...args: any[]) => any> = TF & (TF extends (...args: any[]) => infer TR ? TR extends (...args: any[]) => infer R2 ? AddSpyOnFunction<TR> : TR extends Promise<any> ? AddSpyOnPromise<TR> : TR extends Observable<any> ? AddSpyOnObservable<TR> : AddSpyOnFunction<TF> : never);
export declare type Unpacked<T> = T extends Array<infer U1> ? U1 : T extends (...args: any[]) => infer U2 ? U2 : T extends Promise<infer U3> ? U3 : T extends Observable<infer U4> ? U4 : T;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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