Code Monkey home page Code Monkey logo

micro-should's Introduction

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.

micro-should's People

Contributors

paulmillr avatar shvaikalesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

micro-should's Issues

Allow only and skip on `describe`.

As the test suite grows in test count, it can become time consuming to run all of the tests every time while you are iterating on a particular subset. It would be nice to be able to only run a specific describe set of tests at a time, or skip a particularly slow running set of tests without having to skip them all individually.

Also, if there are multiple should.only, only a single one (the last one) will actually run so even if you have parameterized tests you cannot constrain to a whole suite of them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.