Skip to content

chasenyc/bianca.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bianca.js

A simple test framework for JavaScript.

alt text

Bianca is a lightweight behavior-driven development framework for testing JavaScript code. Bianca.js is built completely with vanilla JavaScript and requires no other libraries to run. It does not need a DOM and uses basic syntax for easy use. This test suite was inspired by Jasmine and Secrets of the JavaScript Ninja.

Download/Use

To use simply clone this repository or download here. Simply look in the SpecRunner.html file for where to include both the source code as well as the spec files. Commented out code will indicate where to place the script tags.

Suites: describe your tests

A test suite begins with a call to the global bianca.js function describe with two parameters: a string and a function. The string is the name of the suite and the function is the block of code that implements the suite.

Specs: should comply with your specifications

Specs are defined by calling the global bianca.js function should, which, like describe takes a string and a function. The string is the explanation of what this spec addresses in regard to the suite. A spec contains one or more expectations that test the source code. Unless all expectations pass, the spec is considered failing. One more important note is that after one expectation fails, the spec will cease to run and all other expectations will be ignored.

Expectations: expect your code to function in a certain way

Expectations are constructed with the expect function. It takes in a value and is chained with a matcher and which returns a boolean response.

Matchers

Each matcher implements a boolean comparison between the actual and the expected. This will then lead to the passing or failing of the spec.

Current matchers available:

  • toEqual which checks for equality
  • toNotEqual which checks for inequality
  • toBeGreaterThan checks if greater than a value
  • toBeLessThan checks if less than a value
  • toBeCloseTo checks if close to a given target, takes in a threshold
  • toThrowError checks if a function throws an error
  • toNotThrowError checks if a function does not throw an error

Sample Spec Code:

describe("Basics", function () {
  should("toEqual checks if argument passed to expect equals second argument", function() {
    var life = 42;

    expect(life).toEqual(42);
  })

  should("toNotEqual checks that there is not equality", function() {
    var sum = function(numOne, numTwo) {
      return (numOne + numTwo);
    }
    expect(sum(2,2)).toNotEqual(5);
  })

  should("toBeGreaterThan and toBeLessThan work as expected", function() {
    var a = 2;
    expect(a).toBeGreaterThan(1);
    expect(a).toBeLessThan(3);
  })

  should("toBeCloseTo takes in a threshold and a target", function() {
    var a = 2;
    expect(a).toBeCloseTo(1, 3);
  })

  should("toThrowError checks if a function throws an error when invoked", function() {
    function foo() {
      throw 'bar'
    }

    function bar() {
      return 'foo'
    }
    expect(foo).toThrowError();
    expect(bar).toNotThrowError();
  })
});

All of these tests return passing.

About

A simple test framework for JavaScript.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published