Socket
Book a DemoInstallSign in
Socket

@quoin/node-test-helpers-core

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@quoin/node-test-helpers-core

Core test helpers library for nodeJS with Chai plugins

2.0.1
latest
Source
npmnpm
Version published
Maintainers
2
Created
Source

node-test-helpers-core

Build Status

This is a helper library to limit the number of packages to install in your project. Because of the nature of chai plugins, this library only include the core for your tests. You will need to write a local helper to include all your chai plugins,

To install

To add the library to your project:

npm install --save-dev @quoin/node-test-helpers-core

Usage

local-helper.js:

const testHelpers = require('@quoin/node-test-helpers-core');
const dirtyChai = require('dirty-chai');

testHelpers.chai.use(dirtyChai);

module.exports = testHelpers;

file.unit.test.js:

const testHelpers = require('./local-helpers');
const moduleToTest = require('./index');

const expect = testHelpers.expect;

describe("index", () => {
    it("should export a function with 2 params", () => {
        expect(index).to.be.a('function').to.have.lengthOf(2);
    });
});

See the lib/index.js file to see what libraries are imported and refer to their respective documentation.

Examples

createMocks, createRequest and createResponse

See node-mocks-http for more details.

it("should set headers", () => {
  const {req, res} = testHelpers.createMocks();
});

verifyHal

To verify that a portion of a response (or the entire reponse is a valid HAL:

it("should be a valid HAL", () => {
    const someResponseFromServer = requestCall();
    testHelpers.verifyHal(someResponseFromServer.body);
});

verifyProperties

To verify all properties of an object:

it("should expose known properties", () => {
  const clone = _.clone(moduleToTest);

  testHelpers.verifyProperties(clone, 'string', [
    'prop1',
    'prop2'
  ]);

  testHelpers.verifyProperties(clone, 'function', [
    'prop3',
    'prop4'
  ]);

  expect(clone).to.deep.equal({});
});

Keywords

nodejs

FAQs

Package last updated on 22 Jun 2021

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.