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

@need-some/test

v0.1.4

Published

Need Some Testing enhancement

Downloads

8

Readme

need-some-test.js

Build Status License: MIT npm version need-some/test Dependencies

need-some is a collection of small yet useful functions. The test package is a unit testing extension for javascript and typescript.

Installation

Simply install as dev dependency

npm install @need-some/test --save-dev

Jasmine

Parameterized tests

Suites defined by describe or tests defined by it can be parameterized using the corresponding pdescribe or pit with an array of parameters.

Usage

Simple example in Typescript:

import { pit } from '@need-some/test/parameterizedtest';

describe('Sample', () => {
	const params = [
		{
			title: 'identical numbers',
			a: 1,
			b: 1
		}, {
			title: 'different numbers',
			a: 1,
			b: 2
		}
	];
	pit('should compute less or equals for ${title}', params, (param) => {
		expect(param.a <= param.b).toBeTruthy();
	});
});

Similar to the Jasmine it and describe, the tests can be focussed with a prefix f or skipped using the prefix x. The modifier is applied to all parameters.

Parameterized Unit Test with pit / fpit / xpit

pit creates an unit test for each parameter. The title of each test is produced by replacing ${title} by the title of each param.

pit(title: string, params: S[], assertion: (S)=> void, timeout?: number): void

All generated tests can be focussed by using fpit. All generated tests are added to the set of focussed tests.

fpit(title: string, params: S[], assertion: (S)=> void, timeout?: number): void

All generated tests are set pending by using xpit. The tests will not be executed.

xpit(title: string, params: S[], assertion: (S)=> void, timeout?: number): void

Parameterized Suite with pdescribe / fpdescribe / xpdescribe

pdescribe creates suits for each parameter. The title of each suite is produced by replacing ${title} by the title of each param.

pdescribe(title: string, params: S[], tests: (S)=> void): void

All generated suits can be focussed by using fpdescribe. All contained tests in these suits are added to the set of focussed tests.

fpdescribe(title: string, params: S[], tests: (S)=> void): void

All generated suits are set pending by using xpdescribe. All contained tests are marked pending as well and not executed.

xpdescribe(title: string, params: S[], tests: (S)=> void): void

Set parameters to focussed or pending

Single parameters can also be set to focussed or pending by setting a flag fit or xit in the parameter

const params = [
	{
		fit: true,
		title: 'identical numbers',
		a: 1,
		b: 1
	}, {
		title: 'different numbers',
		a: 1,
		b: 2
	}, {
		xit: true,
		title: 'different numbers in unexpected order',
		a: 2,
		b: 1
	}
];

If both xit and fit are set, the test is marked pending (the fit is ignored)

If focussed params, tests or suites are nested within pending suits, the result may not be exactly as expected.

Title generation

The title of a suite or test is either created by replacing ${title} by the parameter title or calling a function given in the test definition.

'The test with title ${title}'

If parameters are necessary, a function may be used to create the string

function(param, title) { return title + ' '+param.arg1; }

Of course arrow functions are also fine

(param, title) => title + ' ' + param.arg1

This can also be used with template strings to be even shorter

(param, title) => `The test with title ${title} and param ${param.arg}`

The title is contained in the param object, so the second parameter of the function is optional

p => `The test with title ${p.title} and param ${p.arg}`