0.3.18 • Published 6 years ago

mockumentary v0.3.18

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

Mockumentary

Mockumentary is a library for creating mock objects from scratch using a concise syntax.

Creating a new mock class

var Mock = new Mockumentary({
    foo: ()=> true,
    bar: false,
})

The new Mock class has a method foo that will always return true and a property bar with the value false.

Instantiating a mock object

var mock = new Mock()

The new mock object has a method foo and a property bar because it does not add to or override the default Mock specification.

var mock = new Mock({
    bam: function () {
        return true
    }
})

This new mock object has a method bam that is a custom function which will be set as the value for mock.bam.

Specifying multiple return values

var mock = new Mock({
    foo: ()=> [
        true,
        true,
        false,
    ],
})

When an array of values is specified then calls to foo will return each value in order. If the number of calls exceeds the length of the list then it will start over at the first element.

Specifying multiple custom methods

var mock = new Mock({
    bam: ()=> [
        ()=> true,
        ()=> true,
        ()=> false,
    ]
})

Mockumentary treats plain functions as regular values and uses arrow functions to specify functions that should be called.

When bam is called the arrow function will be called with the original arguments for bam and its return value will be returned.

Creating a single mock method

var method = new Mock([
    true,
    true,
    false,
])

If an array is passed to instantiate a new Mock then only a single method will be created instead of an object.

0.3.18

6 years ago

0.3.17

7 years ago

0.3.16

7 years ago

0.3.15

7 years ago

0.3.14

7 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago