Socket
Socket
Sign inDemoInstall

chai-callslike

Package Overview
Dependencies
127
Maintainers
8
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chai-callslike

A simple sinon-chai assertion to validate many aspects of stub calls


Version published
Weekly downloads
96
decreased by-7.69%
Maintainers
8
Install size
10.7 MB
Created
Weekly downloads
 

Changelog

Source

1.2.8

  • d4eabe9 Merge pull request #22 from Codibre/update-readme-file
  • 77b65f2 docs: adding some information to the readme file

Readme

Source

chai-callslike

build test lint Test Coverage Maintainability Packages npm version

A simple assertion to validate many aspects of stub calls. It is supposed to use with sinon + chai.

How it works

expect(stub).callsLike

Will validate the exactly interaction with the mocked method, which is:

  • How many times has been called;
  • Which parameters have been passed to it;
  • In what order the calls happened.

How to use?

It is pretty simple to setup the chai-callslike in your tests:

import chai from 'chai'
import {callsLike} from 'chai-callslike'

chai.use(callsLike)

Just pass the stub in the first parameter and, in the others, arrays with the set of parameters each calls had received.

expect(myStub).callsLike(
  ['param1call1', 'param2call1', 'param3call1'],
  ['param1call2', 'param2call2', 'param3call2'],
 );

If you want to check if the stub had never been called, pass just the stub:

expect(myStub).callsLike();

If you expect the stub to have been called with no parameters, pass empty arrays:

expect(myStub).callsLike([], [], [])

(in this example, myStub have been called three times with no parameters)

You can also use sinon matchers to validate the parameters instead of exact values:

expect(myStub).callsLike(
  [sinon.match.object, sinon.match.string, sinon.match(/.+foo.+goo/)]
 );

The generated log will look pretty as this:

If if didn't show up, take a look in the resources folder!

For more info look into the Full API Reference.

Keywords

FAQs

Last updated on 01 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc