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

promise-matchers

v0.9.6

Published

Custom jasmine matchers for testing asynchronous javascript

Downloads

70

Readme

promise-matchers

This library introduces a simple set of custom Jasmine matchers for use with asynchronous JavaScript. It can be used with any promises library that implements the Promises/A+ specification, such as Q, Promise, RSVP, WinJS or jQuery.

Matchers

expect(promise).toHaveBeenResolved(done);
expect(promise).toHaveBeenResolvedWith(done, expectation);
expect(promise).toHaveBeenRejected(done);
expect(promise).toHaveBeenRejectedWith(done, expectation);

Usage

Either you use in your browser jasmine test runner by adding it after the script-tag jasmine.js:

<script src="promise-matchers/src/promise-matchers.js"></script>

Or when using jasmine-node you can simply install the matchers via:

npm install promise-matchers --save -dev

And make them available in your spec-file:

require('promise-matchers');
describe(...);

// or via requirejs (assuming your specs are within PROJECT_ROOT/test):
require([
  '../node_modules/promise-matchers/src/promise-matchers.js',
], function() {
  describe(...);
});

Examples

it('succeeds', function(done) {
    var promise = foo();
    expect(promise).toHaveBeenResolved(done);
});
it('fails', function(done) {
    var promise = foo();
    expect(promise).toHaveBeenRejected(done);
});
it('succeeds with value of 3', function(done) {
    var promise = foo();
    expect(promise).toHaveBeenResolvedWith(done, function(result) {
        expect(result).toBe(3);
    });
});
it('fails without saving', function(done) {
    var save = spyOn(Bar, 'save');
    var promise = foo();
    expect(promise).toHaveBeenRejectedWith(done, function() {
        expect(save).not.toHaveBeenCalled();
    });
});

Notes

  1. If a promise with an expectation of toHaveBeenResolved or toHaveBeenResolvedWith is rejected, the matcher fails with the message Expected promise to have been resolved or with the message Expected promise to have been resolved but it was rejected with: [possible promise reject message].
  2. If a promise with an expectation of toHaveBeenRejected or toHaveBeenRejectedWith is resolved, the matcher fails with the message Expected promise to have been rejected but it was resolved with: [possible promise resolve value].
  3. If an expectation passed to toHaveBeenResolvedWith or toHaveBeenRejectedWith fails, the matcher fails with that expectation's failure message.
  4. If an expectation passed to toHaveBeenResolvedWith or toHaveBeenRejectedWith throws an exception, the matcher fails with the exception text.
  5. These matchers will not behave properly with not.