<!DOCTYPE html>
<html>
<head>
<link data-require="jasmine@*" data-semver="2.4.1" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.css" />
<script data-require="jasmine@*" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js"></script>
<script data-require="jasmine@*" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine-html.js"></script>
<script data-require="jasmine@*" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/boot.js"></script>
<script data-require="rxjs@5.0.3" data-semver="5.0.3" src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script>
<script src="script.js"></script>
</head>
<body>
</body>
</html>
// Testing throttling example
var throttleTimeWindowDuration = 2 * 1000; /* 2 seconds */
function throttleTest() {
var unthrottleTimedStream = new Rx.Subject();
var source = unthrottleTimedStream.throttleTime(throttleTimeWindowDuration);
var result = {
emitCounter: 0,
unthrottleTimedStream
};
var subscription = source.subscribe(
function() {
result.emitCounter++;
});
return result;
}
describe('using jasmine.clock', function() {
beforeEach(() => {
jasmine.clock().install();
});
afterEach(() => {
jasmine.clock().uninstall();
});
it('allows to test throttling synchronously', function() {
var throttleTestResult = throttleTest();
throttleTestResult.unthrottleTimedStream.next();
throttleTestResult.unthrottleTimedStream.next();
jasmine.clock().tick(throttleTimeWindowDuration);
throttleTestResult.unthrottleTimedStream.next();
throttleTestResult.unthrottleTimedStream.next();
jasmine.clock().tick(throttleTimeWindowDuration);
throttleTestResult.unthrottleTimedStream.next();
jasmine.clock().tick(throttleTimeWindowDuration);
throttleTestResult.unthrottleTimedStream.next();
expect(throttleTestResult.emitCounter).toBe(4);
});
});