New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

p-test-js

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-test-js

For parameterized javascript unit testing

latest
Source
npmnpm
Version
2.1.10
Version published
Maintainers
1
Created
Source

parameterized-unit-tests-helper

This module is to help writing javascript unit testing in the parameterized way

It supports both mocha@7.x.x and jest@26.x.x It also should supports any test frameworks whose has the following functionalities

interface TestProvider {
  describe: Function;
  it: Function;
  before?: Function;
  after?: Function;
  beforeAll?: Function;
  afterAll?: Function;
  beforeEach: Function;
  afterEach: Function;
}

How to install?

npm i --save-dev p-test-js
or
yarn add --dev p-test-js

Initialize (Mocha)

import Mocha from "mocha";
import { getDecorators } from 'p-test-js'

const {
  testsuite,
  testname,
  testcase,
  before,
  after,
  beforeEach,
  afterEach,
} = getDecorators(Mocha);

Initialize (Jest)

import Jest from "@jest/globals";
import { getDecorators } from 'p-test-js'

const {
  testsuite,
  testname,
  testcase,
  before,
  after,
  beforeEach,
  afterEach,
} = getDecorators(Jest);

Example 1 typescript (mocha)

import { expect } from 'chai'

@testsuite("Example test suite #1")
@before(() => console.log("Before #1"))
@after(() => console.log("After #1"))
export class DumpCalculatorTest1 {
  @testcase(1, 2, 3)
  @testcase(2, 2, 4)
  superDumpPlusTest(a: number, b: number, expected: number): void {
    const r = a + b;
    expect(r).to.be.eq(expected);
  }
}

Output 1

  Example test suite #1
Before #1
    ✓ superDumpPlusTest with 1,2,3
    ✓ superDumpPlusTest with 2,2,4
After #1

Example 2 typescript (mocha)

import { expect } from 'chai'

@testsuite("Example test suite #2")
@before(() => console.log("Before #2"))
@after(() => console.log("After #2"))
@beforeEach(() => console.log("Before each #2"))
@afterEach(() => console.log("After each #2"))
export class DumpCalculatorTest2 {
  @testname("Example test case #2")
  @testcase(1, 2, 3)
  @testcase(2, 2, 4)
  superDumpPlusTest(a: number, b: number, expected: number): void {
    const r = a + b;
    expect(r).to.be.eq(expected);
  }
}

Output 2

  Example test suite #2
Before #2
Before each #2
    ✓ Example test case #2 with 1,2,3
After each #2
Before each #2
    ✓ Example test case #2 with 2,2,4
After each #2
After #2

To-do

  • add automated deployment ✓

Keywords

parameterised

FAQs

Package last updated on 10 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts