@reactivex/rxjs
Version:
Reactive Extensions for modern JavaScript
334 lines (324 loc) • 20.6 kB
HTML
<html>
<head>
<meta charset="utf-8">
<base data-ice="baseUrl" href="../../../">
<title data-ice="title">spec-js/operators/sequenceEqual-spec.js | RxJS API Document</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
<script src="script/prettify/prettify.js"></script>
<script src="script/manual.js"></script>
<script data-ice="userScript" src="user/script/0-Rx.js"></script>
<script data-ice="userScript" src="user/script/1-devtools-welcome.js"></script>
<script data-ice="userScript" src="user/script/2-custom-manual-styles.js"></script>
<script data-ice="userScript" src="user/script/3-decision-tree-widget.min.js"></script>
<script data-ice="userScript" src="user/script/4-theme-toggler.js"></script>
<link data-ice="userStyle" rel="stylesheet" href="user/css/0-main.css">
</head>
<body class="layout-container" data-ice="rootContainer">
<header>
<a href="./">Home</a>
<a href="./manual/index.html" data-ice="manualHeaderLink">Manual</a>
<a href="identifiers.html">Reference</a>
<a href="source.html">Source</a>
<a href="test.html" data-ice="testLink">Test</a>
<a data-ice="repoURL" href="https://github.com/ReactiveX/RxJS" class="repo-url-github">Repository</a>
<div class="search-box">
<span>
<img src="./image/search.png">
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
</span>
<ul class="search-result"></ul>
</div>
</header>
<nav class="navigation" data-ice="nav"><div>
<ul>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-AsyncSubject">AsyncSubject</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-BehaviorSubject">BehaviorSubject</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Notification">Notification</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Observable">Observable</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-ReplaySubject">ReplaySubject</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Scheduler">Scheduler</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-AnonymousSubject">AnonymousSubject</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Subject">Subject</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-SubjectSubscriber">SubjectSubscriber</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Subscriber">Subscriber</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Subscription">Subscription</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-Rx.Scheduler">Rx.Scheduler</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-Rx.Symbol">Rx.Symbol</a></span></span></li>
<li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">observable</div><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-ConnectableObservable">ConnectableObservable</a></span></span></li>
<li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">observable/dom</div><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-AjaxError">AjaxError</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-AjaxResponse">AjaxResponse</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-AjaxTimeoutError">AjaxTimeoutError</a></span></span></li>
<li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">operator</div><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-GroupedObservable">GroupedObservable</a></span></span></li>
<li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">scheduler</div><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Action">Action</a></span></span></li>
<li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">util</div><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-ArgumentOutOfRangeError">ArgumentOutOfRangeError</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-EmptyError">EmptyError</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-ObjectUnsubscribedError">ObjectUnsubscribedError</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-TimeoutError">TimeoutError</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-UnsubscriptionError">UnsubscriptionError</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-root">root</a></span></span></li>
</ul>
</div>
</nav>
<div class="content" data-ice="content"><h1 data-ice="title">spec-js/operators/sequenceEqual-spec.js</h1>
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">var booleans = { T: true, F: false };
/** @test {sequenceEqual} */
describe('Observable.prototype.sequenceEqual', function () {
asDiagram('sequenceEqual(observable)')('should return true for two equal sequences', function () {
var s1 = hot('--a--^--b--c--d--e--f--g--|');
var s1subs = '^ !';
var s2 = hot('-----^-----b--c--d-e-f------g-|');
var s2subs = '^ !';
var expected = '-------------------------(T|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(s1subs);
expectSubscriptions(s2.subscriptions).toBe(s2subs);
});
it('should return false for two sync observables that are unequal in length', function () {
var s1 = cold('(abcdefg|)');
var s2 = cold('(abc|)');
var expected = '(F|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
});
it('should return true for two sync observables that match', function () {
var s1 = cold('(abcdefg|)');
var s2 = cold('(abcdefg|)');
var expected = '(T|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
});
it('should return true for two observables that match when the last one emits and completes in the same frame', function () {
var s1 = hot('--a--^--b--c--d--e--f--g--|');
var s1subs = '^ !';
var s2 = hot('-----^--b--c--d--e--f--g------|');
var s2subs = '^ !';
var expected = '-------------------------(T|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(s1subs);
expectSubscriptions(s2.subscriptions).toBe(s2subs);
});
it('should return true for two observables that match when the last one emits and completes in the same frame', function () {
var s1 = hot('--a--^--b--c--d--e--f--g--|');
var s1subs = '^ !';
var s2 = hot('-----^--b--c--d--e--f---------(g|)');
var s2subs = '^ !';
var expected = '-------------------------(T|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(s1subs);
expectSubscriptions(s2.subscriptions).toBe(s2subs);
});
it('should error with an errored source', function () {
var s1 = hot('--a--^--b---c---#');
var s2 = hot('--a--^--b---c-----|');
var expected = '-----------#';
var sub = '^ !';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(sub);
expectSubscriptions(s2.subscriptions).toBe(sub);
});
it('should error with an errored compareTo', function () {
var s1 = hot('--a--^--b---c-----|');
var s2 = hot('--a--^--b---c---#');
var expected = '-----------#';
var sub = '^ !';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(sub);
expectSubscriptions(s2.subscriptions).toBe(sub);
});
it('should error if the source is a throw', function () {
var s1 = cold('#'); // throw
var s2 = cold('---a--b--c--|');
var expected = '#'; // throw
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected);
});
it('should never return if source is a never', function () {
var s1 = cold('------------'); // never
var s2 = cold('--a--b--c--|');
var expected = '------------'; // never
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected);
});
it('should never return if compareTo is a never', function () {
var s1 = cold('--a--b--c--|');
var s2 = cold('------------'); // never
var expected = '------------'; // never
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected);
});
it('should return false if source is empty and compareTo is not', function () {
var s1 = cold('|'); // empty
var s2 = cold('------a------');
var expected = '------(F|)';
var subs = '^ !';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(subs);
expectSubscriptions(s2.subscriptions).toBe(subs);
});
it('should return false if compareTo is empty and source is not', function () {
var s1 = cold('------a------');
var s2 = cold('|'); // empty
var expected = '------(F|)';
var subs = '^ !';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(subs);
expectSubscriptions(s2.subscriptions).toBe(subs);
});
it('should return never if compareTo is empty and source is never', function () {
var s1 = cold('-');
var s2 = cold('|');
var expected = '-';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected);
});
it('should return never if source is empty and compareTo is never', function () {
var s1 = cold('|');
var s2 = cold('-');
var expected = '-';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected);
});
it('should error if the comparor errors', function () {
var s1 = hot('--a--^--b-----c------d--|');
var s1subs = '^ !';
var s2 = hot('-----^--------x---y---z-------|');
var s2subs = '^ !';
var expected = '-------------#';
var i = 0;
var source = s1.sequenceEqual(s2, function (a, b) {
if (++i === 2) {
throw new Error('shazbot');
}
return a.value === b.value;
});
var values = {
a: null,
b: { value: 'bees knees' },
c: { value: 'carpy dumb' },
d: { value: 'derp' },
x: { value: 'bees knees', foo: 'lol' },
y: { value: 'carpy dumb', scooby: 'doo' },
z: { value: 'derp', weCouldBe: 'dancin, yeah' }
};
expectObservable(source).toBe(expected, Object.assign({}, booleans, values), new Error('shazbot'));
expectSubscriptions(s1.subscriptions).toBe(s1subs);
expectSubscriptions(s2.subscriptions).toBe(s2subs);
});
it('should use the provided comparor', function () {
var s1 = hot('--a--^--b-----c------d--|');
var s1subs = '^ !';
var s2 = hot('-----^--------x---y---z-------|');
var s2subs = '^ !';
var expected = '-------------------------(T|)';
var source = s1.sequenceEqual(s2, function (a, b) { return a.value === b.value; });
var values = {
a: null,
b: { value: 'bees knees' },
c: { value: 'carpy dumb' },
d: { value: 'derp' },
x: { value: 'bees knees', foo: 'lol' },
y: { value: 'carpy dumb', scooby: 'doo' },
z: { value: 'derp', weCouldBe: 'dancin, yeah' }
};
expectObservable(source).toBe(expected, Object.assign({}, booleans, values));
expectSubscriptions(s1.subscriptions).toBe(s1subs);
expectSubscriptions(s2.subscriptions).toBe(s2subs);
});
it('should return false for two unequal sequences, compareTo finishing last', function () {
var s1 = hot('--a--^--b--c--d--e--f--g--|');
var s1subs = '^ !';
var s2 = hot('-----^-----b--c--d-e-f------z-|');
var s2subs = '^ !';
var expected = '-----------------------(F|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(s1subs);
expectSubscriptions(s2.subscriptions).toBe(s2subs);
});
it('should return false for two unequal sequences, early wrong value from source', function () {
var s1 = hot('--a--^--b--c---x-----------|');
var s1subs = '^ !';
var s2 = hot('-----^--b--c--d--e--f--|');
var s2subs = '^ !';
var expected = '----------(F|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(s1subs);
expectSubscriptions(s2.subscriptions).toBe(s2subs);
});
it('should return false when the source emits an extra value after the compareTo completes', function () {
var s1 = hot('--a--^--b--c--d--e--f--g--h--|');
var s1subs = '^ !';
var s2 = hot('-----^--b--c--d-|');
var s2subs = '^ !';
var expected = '------------(F|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(s1subs);
expectSubscriptions(s2.subscriptions).toBe(s2subs);
});
it('should return false when the compareTo emits an extra value after the source completes', function () {
var s1 = hot('--a--^--b--c--d-|');
var s1subs = '^ !';
var s2 = hot('-----^--b--c--d--e--f--g--h--|');
var s2subs = '^ !';
var expected = '------------(F|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
expectSubscriptions(s1.subscriptions).toBe(s1subs);
expectSubscriptions(s2.subscriptions).toBe(s2subs);
});
it('should return true for two empty observables', function () {
var s1 = cold('|');
var s2 = cold('|');
var expected = '(T|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
});
it('should return false for an empty observable and an observable that emits', function () {
var s1 = cold('|');
var s2 = cold('---a--|');
var expected = '---(F|)';
var source = s1.sequenceEqual(s2);
expectObservable(source).toBe(expected, booleans);
});
it('should return compare hot and cold observables', function () {
var s1 = hot('---a--^---b---c---d---e---f---g---h---i---j---|');
var s2 = cold('----b---c-|');
var expected1 = '------------(F|)';
var subs1 = '^ !';
var delay = '-------------------|';
var s3 = cold('-f---g---h---i---j---|');
var expected2 = ' ---------------------(T|)';
var subs2 = ' ^ !';
var test1 = s1.sequenceEqual(s2);
var test2 = s1.sequenceEqual(s3);
expectObservable(test1).toBe(expected1, booleans);
rxTestScheduler.schedule(function () { return expectObservable(test2).toBe(expected2, booleans); }, time(delay));
expectSubscriptions(s2.subscriptions).toBe(subs1);
expectSubscriptions(s3.subscriptions).toBe(subs2);
});
});
//# sourceMappingURL=sequenceEqual-spec.js.map</code></pre>
</div>
<footer class="footer">
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.4.8)</span></a>
</footer>
<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>