Socket
Socket
Sign inDemoInstall

micro-should

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    micro-should

Simplest zero-dependency testing framework, a drop-in replacement for Mocha


Version published
Weekly downloads
299
decreased by-50.17%
Maintainers
1
Install size
10.0 kB
Created
Weekly downloads
 

Readme

Source

micro-should

Simplest zero-dependency testing framework, a drop-in replacement for Mocha.

Supports async cases. Works with any assertion library.

  • should(title, case) (or it(title, case)) syntax
  • should.only(title, case) allows to limit tests to only one case
  • should.skip(title, case) allows to skip functions instead of commenting them out
  • describe(prefix, cases) for nested execution
  • should.run() must always be executed in the end
  • should.runParallel() for CPU-intensive tasks, would ramp up threads equal to CPU count

npm install micro-should

Usage

const { should } = require('micro-should');
const assert = require('assert'); // You can use any assertion library (e.g. Chai or Expect.js), example uses built-in nodejs

should('add two numbers together', () => {
  assert.equal(2 + 2, 4);
});

should('catch errors', () => {
  assert.throws(() => {
    throw new Error('invalid');
  });
});

should('produce correct promise result', async () => {
  const fs = require('fs').promises;
  const data = await fs.readFile('README.md', 'utf-8');
  assert.ok(data.includes('Minimal testing'));
});

// should.only("execute only one test", () => {
//   assert.ok(true);
// });

// should.skip("disable one test by using skip", () => {
//   assert.ok(false); // would not execute
// })

// Nested
const { describe } = require('micro-should');
describe('during any time of day', () => {
  describe('without hesitation', () => {
    should('multiply two numbers together', () => {
      assert.equal(2 * 2, 4);
    });

    should('multiply three numbers together', () => {
      assert.equal(3 * 3 * 3, 27);
    });
  });
});

// Execute this at the end of a file.
should.run();

License

MIT (c) Paul Miller (https://paulmillr.com), see LICENSE file.

Keywords

FAQs

Last updated on 26 Jan 2023

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc