Giter VIP home page Giter VIP logo

jasmine-promises's Introduction

jasmine-promises

Travis CI build status

Write asynchronous tests easier by returning Promises from your spec functions.

No need to call done and done.fail.

describe('my fancy thing', function () {
	beforeEach(function () {
		return doSomePreparatoryTaskThatIsAsync();
	});

    it('should be extra fancy', function () {
        return fancyAsync().then(function (thing) {
            expect(thing).toBeFancy();
        });
    });
});

Benefits:

  • Works with any thenable. ✓
  • Simply return a promise from a test -- no need to call done and done.fail
  • Automatic error handling when using native Promise's'. When writing such tests manually, you have to explictly catch the error with .catch and then pass the error to done.fail or rethrow. Unhandled Promise rejections are gobbled up so if you forget to do this you can miss out on debugging info. ✓
  • Works with it, fit, beforeEach, afterEach, beforeAll, and afterAll. ✓

Installation

Note: only compatible with Jasmine 2 at this point.

npm install jasmine-promises --save-dev

Then ensure that jasmine-promises is loaded before your tests are loaded. This can be done by either...

manually requiring the module at the top of your test file(s) e.g. if using browserify:

require('jasmine-promises');

describe('my fancy thing', function () {
	it('should be extra fancy', function () {
		return fancyAsync().then(function (thing) {
			expect(thing).toBeFancy();
		});
	});
});

loading it via your test runner e.g. Karma:

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      'node_modules/jasmine-promises/dist/jasmine-promises.js',
      'test/**/*.spec.js'
    ],

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.