npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

expect-called

v0.4.0

Published

for control expected calls to any function in test suites

Readme

expect-called

NPM Version NPM Downloads Linux Build Windows Build Test Coverage

If you want to verify that a function was called in the way you expect.

Install

$ npm install expect-called

API

expectedCalled.control(object, functionName, [opts])

Creates a function wrapper for object[functionName], the wrapper function will register de parameters used to call the function (included this) and then calls de original function and returns the returned value.

Returns a control object

opts | type | use for ---------|---------|----- withThis | boolean | register this object in calls returns | Array | create a mock function that returns each of the elements in the list one by one mocks | Array of function | funcions to call instead original function. Each element of the array is called in each call with the same parámeters and returning the corresponding returned value

control.call

Is the array property that contains each call to the function. Each call generates a object with two properties {This: ..., args: [... ]}

control.stopControl()

Stops the control function.

expectedCalled.global

SYMBOL that represents the root object in control.call

Example

var expect = require('expect.js'); // needed for the example

var expectCalled = require('expect-called');

var myModule={
    upper:function(word){
        return word.substring(0,1).toUpperCase()+word.substring(1);
    },
    cammel:function(phrase){
        // function to TEST and to CONTROL
        // must call upper
    }
}

describe('this test',function(){
  it('should call intermediate function',function(){
    var control = expectCalled.control(myModule,'upper');
    var phrase = 'this is my camel';
    var camelPhrase = myModule.cammel(phrase);
    expect(camelPhrase).to.eql('ThisIsMyCamel');
    expect(control.calls).to.eql([
        ['this'],
        ['is'],
        ['my'],
        ['camel']
    ]);
    control.stopControl();
  });
});

Notes

  • Not usefull for local functions that do not belong to a object
  • Not control de returned value but could specify the returned values (like a mock function)
  • Call to control with the same function name twice without stopping the previous control could generate unexpected results.

License

MIT