Nanometers Per Millisecond
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    shampublic

    Sham

    Sham is a simple and small JavaScript library for mocking.

    sham.spy([name])

    var sum = sham.spy('sum');
     
    sum.args(5, 7); // specify the arguments
    sum.return(12); // set return value
    sum.called(3); // ensure that spy is called three times
     
    sum(2, 3) // this throws an error, because the arguments are wrong
     
    var result = sum(5, 7); // result is now 12
     
    sum.check(); // this throws an error, because sum was called only once

    sham.mock()

    var file = sham.mock();
     
    file.method('read').return('some text').called();
    file.method('write').args('another text').called();
     
    var contents = file.read(); // contents is now 'some text'
     
    file.check(); // this throws an error, because write wasn't called
     
    file.write('another text');
     
    file.check(); // this doesn't throw

    You can generate mocks too:

    function create() {
        var file = sham.mock();
        file.method('read');
        file.method('write');
     
        return file;
    }
     
    var file = create();
     
    file.read.return('some text');
     
    var contents = file.read(); // contents is now 'some text'

    Keywords

    none

    install

    npm i sham

    Downloadsweekly downloads

    10

    version

    0.3.0

    license

    none

    repository

    githubgithub

    last publish

    collaborators

    • avatar