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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jasmine2chai

v1.0.2

Published

Converts Jasmine assertions to chai.js assertions

Downloads

8

Readme

jasmine2chaiBuild StatusJavaScript Style Guide

Introduction

Are you migrating your test suite from Jasmine to Mocha? Are you using chai as your assertion library in Mocha?

While Jasmine and Mocha have a very similar test and assertion syntax, they're just different enough to not work out of the box with each other.

Jasmine2Chai uses jscodeshift to (as accurately as possible) transform your test code into something that is compatible with chai.js assertions, while leaving your code style alone.

Installation

npm install -g jasmine2chai

Usage

Print out a converted file to the terminal (stdout):

jasmine2chai myfile.js

Translations

toBe -> to.be

Jasmine assertion:

expect('taco').toBe('taco');

chai assertion:

expect('taco').to.be('taco');

toEqual -> to.equal

Jasmine assertion:

expect('taco').toEqual('taco');

chai assertion:

expect('taco').to.equal('taco');

toMatch -> to.match

Jasmine assertion:

expect('taco').toMatch(/taco/)

chai assertion:

expect('taco').to.match(/taco/);

toBeDefined -> not.to.be.undefined

Jasmine assertion:

expect('taco').toBeDefined();

chai assertion:

expect('taco').to.not.be.undefined;

toBeUndefined -> to.be.undefined

Jasmine assertion:

expect(undefined).toBeUndefined();

chai assertion:

expect(undefined).to.be.undefined;

toBeNull -> to.be.null

Jasmine assertion:

expect(null).toBeNull();

chai assertion:

expect(null).to.be.null;

toBeTruthy -> to.be.ok

Jasmine assertion:

expect(true).toBeTruthy();

chai assertion:

expect(true).to.be.ok;

toBeFalsy -> to.not.be.ok

Jasmine assertion:

expect(false).toBeFalsy();

chai assertion:

expect(false).to.not.be.ok;

toContain -> to.include

Jasmine assertion:

expect([1, 2, 3]).toContain(1);

chai assertion:

expect([1, 2, 3]).to.include(1);

toBeLessThan -> to.be.below

Jasmine assertion:

expect(1).toBeLessThan(2);

chai assertion:

expect(1).to.be.below(2);

toBeGreaterThan -> to.be.above;

Jasmine assertion:

expect(2).toBeGreaterThan(1);

chai assertion:

expect(2).to.be.above(1);

toBeCloseTo -> to.be.closeTo

Jasmine assertion:

expect(2).toBeCloseTo(1,1);

chai assertion:

expect(2).to.be.closeTo(1,1);

toThrow -> to.throw

Jasmine assertion:

expect(function() { throw new Error('hi')).toThrow();

chai assertion:

expect(function() { throw new Error('hi')).to.throw();

toThrowError -> to.throw

Jasmine assertion:

expect(foo).toThrowError("foo bar baz");
expect(foo).toThrowError(/bar/);
expect(foo).toThrowError(TypeError);
expect(foo).toThrowError(TypeError, "foo bar baz");

chai assertion:

expect(foo).to.throw("foo bar baz");
expect(foo).to.throw(/bar/);
expect(foo).to.throw(TypeError);
expect(foo).to.throw(TypeError, "foo bar baz");

Spy Migrations

Important Note:

You'll need the sinon-chai plugins for this to work. In addition, spyOn calls are not yet translated. This only translates the assertions on spies.

toHaveBeenCalled -> to.have.been.called

Jasmine assertion:

expect(foo.setBar).toHaveBeenCalled();

chai assertion:

expect(foo.setBar).to.have.been.called;

toHaveBeenCalledWith -> to.have.been.calledWith

Jasmine assertion:

expect(foo.setBar).toHaveBeenCalledWith(123);
expect(foo.setBar).toHaveBeenCalledWith(456, 'another param');

chai assertion:

expect(foo.setBar).to.have.been.calledWith(123);
expect(foo.setBar).to.have.been.calledWith(456, 'another param');

toHaveBeenCalledTimes -> to.have.callCount

Jasmine assertion:

expect(foo.setBar).toHaveBeenCalledTimes(2);

chai assertion:

expect(foo.setBar).to.have.callCount(2);