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 5.1.0 to 5.2.0

for-readme/test-angular.jpg

2

package.json
{
"name": "jasmine-auto-spies",
"version": "5.1.0",
"version": "5.2.0",
"repository": {

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

# jasmine-auto-spies
Easy and type safe way to write spies for jasmine tests, for both sync and async (promises, Observables) returning methods.
[![npm version](https://img.shields.io/npm/v/jasmine-auto-spies.svg?style=flat-square)](https://www.npmjs.org/package/jasmine-auto-spies)

@@ -9,2 +11,11 @@ [![npm downloads](https://img.shields.io/npm/dm/jasmine-auto-spies.svg?style=flat-square)](http://npm-stat.com/charts.html?package=jasmine-auto-spies&from=2017-07-26)

<div align="center">
<a href="http://testangular.com/?utm_source=github&utm_medium=link&utm_campaign=jasmine+auto+spies">
<img src="for-readme/test-angular.jpg"
alt="TestAngular.com - Free Angular Testing Workshop - The Roadmap to Angular Testing Mastery"
width="600"
/>
</a>
</div>
## IMPORTANT: compatibility

@@ -47,3 +58,3 @@

or
or

@@ -244,1 +255,49 @@ `npm install -D jasmine-auto-spies`

```
---
## Observable Testing Helper Methods 👀💪
#### `recordObservable(source: Observable<T>): RecordObservableReturnValue<T>`
In order to test more complicated observables,
you can use the `recordObservable` function to "record" all the messages a source observable emits and get them as an array.
**Returns:**
```ts
interface RecordObservableReturnValue<T> {
// Aggregated results Observable that wraps the source observable
recordedResults$: Observable<T[]>;
// completes the recording observable and emits the recorded results.
stopRecording: () => void;
}
```
**Usage:**
```js
it('should record Observable', () => {
const fakeSubject = new Subject();
const myObs$ = fakeSubject.asObservable();
const { recordedResults$, stopRecording } = recordObservable(myObs$);
// This subscribes to the source observable "myObs$" behind the scenes
recordedResults$.subscribe(recordedResults => (actualResults = recordedResults));
fakeSubject.next(1);
fakeSubject.next(2);
fakeSubject.next(3);
// This will emit the "recordedResults" and complete
stopRecording();
expect(actualResults).toEqual([1, 2, 3]);
});
```
Basically, behind the scenes it just uses `takeUntil` and `toArray`.
So the `stopRecording()` function completes the recording observable via `takeUntil` and then returns all the results as an array via `toArray` in the form of `recordedResults$`.
export * from './spy.types';
export { AsyncSpyable } from './async-spyable-decorator';
export { createSpyFromClass } from './create-spy-from-class';
export { recordObservable } from './observables/record-observable';

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

exports.createSpyFromClass = create_spy_from_class_1.createSpyFromClass;
var record_observable_1 = require("./observables/record-observable");
exports.recordObservable = record_observable_1.recordObservable;
//# sourceMappingURL=index.js.map

@@ -21,20 +21,14 @@ "use strict";

}
FakeClass.prototype.syncMethod = function () {
FakeClass.prototype.getSyncValue = function () {
return '';
};
FakeClass.prototype.promiseMethod = function () {
FakeClass.prototype.getPromise = function () {
return Promise.resolve();
};
FakeClass.prototype.providedPromiseMethod = function () {
return Promise.resolve();
};
FakeClass.prototype.observableMethod = function () {
FakeClass.prototype.getObservable = function () {
return rxjs_1.of();
};
FakeClass.prototype.subjectMethod = function () {
FakeClass.prototype.getSubject = function () {
return new rxjs_1.Subject();
};
FakeClass.prototype.providedObservableMethod = function () {
return rxjs_1.of();
};
return FakeClass;

@@ -41,0 +35,0 @@ }());

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