Code Monkey home page Code Monkey logo

jasmine-theories's Introduction

jasmine-theories

This lib adds theories to jasmine. Theories make it possible to run the same testing code with varying inputs. It should only be used when a case holds true for a variety of similar values, such as in the example provided below.

Let's build a spec theory, using theoretically.it:

const theoretically = require("jasmine-theories");

describe("NumberStack", function() {
  theoretically.it("fails if the inserted value is %s (not a number)", [ null, false, new Error("hello"), "str" ], function(insertedValue) {
    const stack = new NumberStack();
    expect(function() {
      stack.push(insertedValue);
    }).toThrow();
  });
});

We would want this output if the cases false and new Error("hello") fails:

Failed: NumberStack fails if the inserted value is false (not a number)
Failed: NumberStack fails if the inserted value is Error: hello (not a number)

The library also supports theoretically.xit, which adds pending tests to the spec.

For use in typescript use classic import statement:

import theoretically from "jasmine-theories"

jasmine-theories's People

Contributors

elevatebart avatar hypesystem avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

jasmine-theories's Issues

Discuss: theoretically.describe

Whereas theoretically.it sets up a single test with a varying value, theoretically.describe would set up an entire section with a varying value:

describe("NumberStack", function() {
  theoretically.describe("empty()", [
    emptyNumberStack,
    numberStackOneElement,
    oneHundredElementNumberStack
  ], function(numberStack) {
    it("removes all elements", function() {
      numberStack.empty();
      expect(numberStack.length).toEqual(0);
      expect(numberStack.pop()).toBeFalsy();
    });
  });
});

(This may not be the best example as it only has a single it in the theoretically.describe. What would be a good example, where several small tests would use the same varying value?)

What are pros/cons of this feature? Should it be added?

Document supported cases

Technically this should support mocha, jasmine and jasmine-node. This should be tested and documented.

Combinations of input

I have this case;

describe("constructor", function() {
    it("fails when at least one object doesn't pass validation", function() {
        var constructor;

        constructor = function() { new Item("something wrong", "something wrong"); };
        expect(constructor).toThrow();

        constructor = function() { new Item(goodFirstArgument, "something wrong"); };
        expect(constructor).toThrow();

        constructor = function() { new Item("something wrong", goodSecondArgument); };
        expect(constructor).toThrow();
    });
});

How could this be handled through jasmine-theories? Maybe adding some functionality that creates permutations of input might be prudent?

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.