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

cucumber-assert

v2.0.1

Published

An assertion library for cucumber.js providing cucumber compatible failures instead of exceptions

Downloads

6,987

Readme

cucumber-assert

Build Status

An assertion library for cucumber.js. It allows assertions in cucumber.js without extra-long stacktraces when an assertion fails.

Installation

npm install cucumber-assert

Note

As of Version 2.0, cucumber-assert uses Promises. If you need the old version without Promises, install Version 1.0.4:

npm install [email protected]

Example usage

var assert = require('cucumber-assert');

module.exports = function() {

	this.Given(/^the field E-Mail is filled with "([^"]*)"/, function (email, callback) {
		var fieldValue = this.getFieldValue('#password');
		assert.equal(fieldValue, email, 'Expected E-Mail to be ' + email).then(callback, callback);
	});

}

Multiple operations

If you need multiple assertions in one step, you can simply wait to resolve all the Promises. Since Promise.all() will resolve with an array of the results, Promise.all(...).then(callback) would result in a broken test, since calling the callback with a parameter tells cucumber, that something went wrong. You can either use Promise.all(...).then(() => callback()) or the provided .all() Method:

var assert = require('cucumber-assert');

module.exports = function() {

	this.Given(/^the form is filled out"/, function (callback) {
		var password = this.getFieldValue('#password');
		var name = this.getFieldValue('#name');
		var tosCheck = this.getFieldValue('#tos');
		
        var promises = [];
		promises.push(assert.notEqual(password, '', 'Expected E-Mail to not be empty'));
		promises.push(assert.notEqual(tosCheck, '', 'Expected Name not to be empty'));
		promises.push(assert.equal(tosCheck, 'checked', 'Expected TOS to be checked'));
        assert.all(promises).then(callback, callback);
	});

}

instead of

		Promise.all(promises).then(() => callback(), () => callback());

Available assertions

Generally cucumber-assert wraps the assertions available by default in node. For reference see http://nodejs.org/api/assert.html

The parameter "callback" is the callback provided by cucumber.js in step definitions and has to be passed always alongside the actual values and expectations.

equal(actual, expected, callback, [message])

assert.equal(password, '', 'Expected E-Mail to be empty').then(callback);

notEqual(actual, expected, [message])

assert.notEqual(password, '', 'Expected E-Mail not to be empty').then(callback);

deepEqual(actual, expected, [message])

assert.deepEqual(nestedObject, expectedNestedObject).then(callback);

notDeepEqual(actual, expected, [message])

assert.notDeepEqual(nestedObject, notExpectedNestedObject).then(callback);

strictEqual(actual, expected, [message])

assert.strictEqual(1, 1).then(callback);

notStrictEqual(actual, expected, [message])

assert.notStrictEqual(1, "1").then(callback);

throws(block, [error], [message])

assert.throws(someFunctionThatThrows).then(callback);

doesNotThrow(block, [message])

assert.doesNotThrow(someFunctionThatDoesNotThrow).then(callback);

ifError(value, [message])

assert.ifError(failsIfThisIsTrue).then(callback);

Changelog

See here