npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rl-async-testing

v1.6.1

Published

Asynchronous testing tools for rxjs and es6 promises

Downloads

27

Readme

Asynchronous test tools for rxjs and Angular

Requires @angular/core since the tooling relies on zones to schedule asynchronous actions

Installation

Install rl-async-testing from npm:

npm install rl-async-testing --save

Configure with Angular-CLI and SystemJs:

/** Map relative paths to URLs. */
const map: any = {
    'rl-async-testing': 'vendor/rl-async-testing'
};

/** User packages configuration. */
const packages: any = {
    'rl-async-testing': {
        main: 'index.js'
    }
};

Modify angular-cli-build.js by adding this line to vendorNpmFiles:

'rl-async-testing/**/*.+(js|js.map)'

Usage

The rlFakeAsync zone can be used in place of the angular fakeAsync zone. The mock tools can be used in conjunction or independently of this, but if combined, the zone will track requests against the mocks and fail the test if there are any requests pending.

import { rlFakeAsync, mock, IMockedPromise, IMockedRequest } from 'rl-async-testing';

interface IMockDataService {
    getWithPromise: IMockedPromise<number>;
    getWithObservable: IMockedRequest<number>;
}

// mock definition
let dataService: IMockDataService = {
    getWithPromise: mock.promise(3),
    getWithObservable: mock.request(3),
};
// or
let dataService: IMockDataService = {
    getWithPromise: mock.promise(x => x.value),
    getWithObservable: mock.request(x => x.value),
};


it('should schedule mock async requests synchronously', rlFakeAsync(() => {
    dataService.getWithPromise();
    dataService.getWithObservable();
    
    // IMockedPromise and IMockedRequest extend Sinon.SinonSpy
    sinon.assert.calledOnce(getWithPromise);
    sinon.assert.calledOnce(getWithObservable);
    
    // assert data not loaded
    
    dataService.getWithPromise.flush();
    dataService.getWithObservable.flush();
    
    // assert data loaded
}));

rxjs scheduling

The rlFakeAsync zone hooks into the rxjs async scheduler to schedule observables based on 'fake' time. This requires using the rlTick wrapper, which calls into angular's tick, but also tracks time for the rxjs scheduler.

import { rlFakeAsync, rlTick, flushMicrotasks } from 'rl-async-testing';

it('should schedule rxjs observables synchronously', rlFakeAsync(() => {
    Observable.of(3).delay(1000);
    
    // assert data not loaded
    
    rlTick(1000);
    flushMicrotasks();
    
    // assert data loaded
}));

Tests

This project uses systemjs and karma to run unit tests.

npm install
npm run build
npm test

Alternately:

npm install
npm run build-test

If you encounter an issue and want to debug it:

npm run test.debug

or

npm run build-test.watch

(Runs tsc in watch mode and concurrently runs the test debugger)