Coder Social home page Coder Social logo

javiergelatti / testy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ngarbezza/testy

0.0 2.0 0.0 154 KB

A very simple JS testing library, for educational purposes. Live at npm at @pmoo/testy.

Home Page: https://ngarbezza.github.io/testy/

License: MIT License

JavaScript 100.00%

testy's Introduction

Testy

ci vulnerabilities dependencies Maintainability package-size downloads activity release-date

A very simple JS testing library, for educational purposes. Live at npm at @pmoo/testy.

Installation

npm install --save-dev @pmoo/testy

Usage

Running a single file

const { suite, test, assert } = require('@pmoo/testy');

suite('a boring test suite', () => {
  test('true is obviously true', () => assert.isTrue(true))
}).run();

(notice the run() at the end)

Running tests from a folder

const { runTesty } = require('@pmoo/testy');

runTesty({ directory: require('path').resolve('./tests') });

And it will run every file under the tests directory, and you can define suites in those files.

In this case, make sure the suites don't have the run() at the end, otherwise they are going to be executed twice.

Examples and available assertions

  • Boolean assertions:
    • assert.that(boolean).isTrue() or assert.isTrue(boolean). It does a strict comparison against true (object === true)
    • assert.that(boolean).isFalse() or assert.isFalse(boolean). It does a strict comparison against false (object === false)
  • Equality assertions:
    • assert.that(actual).isEqualTo(expected) or assert.areEqual(actual, expected).
    • assert.that(actual).isNotEqualTo(expected) or assert.areNotEqual(actual, expected)
    • Equality assertions use a deep object comparison (based on Node's assert module) and fail if objects under comparison have circular references.
    • Equality criteria on non-primitive objects can be specified:
      • Passing an extra two-arg comparator function to isEqualTo(expected, criteria) or areEqual(actual, expected, criteria)
      • Passing a method name that actual object understands: isEqualTo(expected, 'myEqMessage') or areEqual(actual, expected, 'myEqMessage')
      • By default, if actual has an equals method it will be used.
  • Exception testing:
    • assert.that(() => { ... }).raises(error)
    • assert.that(() => { ... }).doesNotRaise(error)
    • assert.that(() => { ... }).doesNotRaiseAnyErrors()
  • Array inclusion:
    • assert.that(collection).includes(object)
    • assert.that(collection).includesExactly(...objects)

Please take a look at the tests folder, you'll find examples of each possible test you can write.

Why?

Why another testing library? The main reason is that we want to keep simplicity, something it's hard to see in the main testing tools out there.

  • Less dependencies: right now, we depend on just one npm package, making the library easy to install and avoiding conflict with other dependencies. This is also good for installing on places where the internet connection is not good and we don't want to download hundreds of libraries.
  • Understandable object-oriented code: we want to use this tool for teaching, so eventually we'll look at the code during lessons, and students should be able to see what is going on, and even contributing at it, with no dark magic involved. Also, we try to follow good OO practices.
  • Unique set of features: we are not following any specification nor trying to copy behavior from other approaches (like the "xUnit" or "xSpec" way).

Contributing

Please take a look at the Contributing section.

testy's People

Contributors

ngarbezza avatar

Watchers

James Cloos avatar  avatar

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.