Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Repository files navigation

should2assert

A tool to help you migrating from should to assert

NPM versionbuild statusTest coverageDavid depsKnown Vulnerabilitiesnpm download

Install

$ npm install should2assert -g

Node.js >= 6.0.0 required

Usage

Usage
$ should2assert [<file|glob> ...]
Options
-c, --cwd current working directory
Examples
$ should2assert test

Example

input file

'use strict';constmm=require('mm');constshould=require('should');describe('test/xxx.test.js',()=>{beforeEach(mm.restore);it('should be ok',()=>{consta='123';constb=123;constc=false;a.should.eql('123');b.should.eql(123);constobj={ a, b, c };obj.should.eql({ a, b, c });obj.a.should.eql(a);a.should.not.eql('321');obj.a.should.not.eql(b);a.should.be.ok();c.should.not.be.ok();obj.b.should.be.ok();obj.c.should.not.be.ok();should.exist(a);should.exist(obj.a);should.not.exist(c);should.not.exist(obj.c);(function(){thrownewError('fail');}).should.throw('fail');(()=>{thrownewError('mock error');}).should.throw(/mockerror/);(()=>{thrownewError('mock error');}).should.throw();obj.should.have.properties('a');obj.should.have.properties(['a','b']);obj.should.have.properties({a: '123',c: false});constoffset=1;constzero=0;conststr='';constobj={};constarr=[];constb=true;constfn=()=>{};consterr=newError('mock error');constdate=newDate();assert(offset);offset.should.be.ok;offset.should.be.ok();zero.should.not.be.ok;zero.should.not.be.ok();zero.should.be.not.ok;zero.should.be.not.ok();offset.should.be.a.Number;offset.should.be.a.Number();str.should.be.a.String;str.should.be.a.String();obj.should.be.an.Object;obj.should.be.an.Object();arr.should.be.an.Array;arr.should.be.an.Array();b.should.be.a.Boolean;b.should.be.a.Boolean();fn.should.be.a.Function;fn.should.be.a.Function();err.should.be.an.Error;err.should.be.an.Error();('123').should.not.be.a.Number;('123').should.not.be.a.Number();(123).should.not.be.a.String;(123).should.not.be.a.String();(123).should.not.be.a.Boolean;(123).should.not.be.a.Boolean();(123).should.not.be.a.Function;(123).should.not.be.a.Function();(123).should.not.be.a.Object;(123).should.not.be.a.Object();(123).should.not.be.an.Array;(123).should.not.be.an.Array();(123).should.not.be.an.Error;(123).should.not.be.an.Error();(123).should.not.be.Array;(123).should.not.be.Error;obj.should.not.be.Error;obj.should.be.an.instanceof(Object);(123).should.be.an.instanceof(Number);(123).should.not.be.an.instanceof(Object);obj.should.not.be.an.instanceof(Number);date.should.be.a.Date;date.should.be.a.Date();obj.should.not.be.a.Date;obj.should.not.be.a.Date();});});

output file

'use strict';constassert=require('assert');constmm=require('mm');describe('test/xxx.test.js',()=>{beforeEach(mm.restore);it('should be ok',()=>{consta='123';constb=123;constc=false;assert(a==='123');assert(b===123);constobj={ a, b, c };assert.deepEqual(obj,{ a, b, c });assert.deepEqual(obj.a,a);assert(a!=='321');assert.notStrictEqual(obj.a,b);assert(a);assert(!c);assert(obj.b);assert(!obj.c);assert(a);assert(obj.a);assert(!c);assert(!obj.c);assert.throws(function(){thrownewError('fail');},'fail');assert.throws(()=>{thrownewError('mock error');},/mockerror/);assert.throws(()=>{thrownewError('mock error');});assert(['a'].every(p=>Object.prototype.hasOwnProperty.call(obj,p)));assert(['a','b'].every(p=>Object.prototype.hasOwnProperty.call(obj,p)));Object.keys({a: '123',c: false}).forEach(p=>assert.deepEqual((obj)[p],({a: '123',c: false})[p]));constoffset=1;constzero=0;conststr='';constobj={};constarr=[];constb=true;constfn=()=>{};consterr=newError('mock error');constdate=newDate();assert(offset);assert(offset);assert(offset);assert(!zero);assert(!zero);assert(!zero);assert(!zero);assert(typeofoffset==='number');assert(typeofoffset==='number');assert(typeofstr==='string');assert(typeofstr==='string');assert(typeofobj==='object');assert(typeofobj==='object');assert(Array.isArray(arr));assert(Array.isArray(arr));assert(typeofb==='boolean');assert(typeofb==='boolean');assert(typeoffn==='function');assert(typeoffn==='function');assert(errinstanceofError);assert(errinstanceofError);assert(typeof'123'!=='number');assert(typeof'123'!=='number');assert(typeof123!=='string');assert(typeof123!=='string');assert(typeof123!=='boolean');assert(typeof123!=='boolean');assert(typeof123!=='function');assert(typeof123!=='function');assert(typeof123!=='object');assert(typeof123!=='object');assert(!Array.isArray(123));assert(!Array.isArray(123));assert(!(123instanceofError));assert(!(123instanceofError));assert(!Array.isArray(123));assert(!(123instanceofError));assert(!(objinstanceofError));assert(objinstanceofObject);assert(123instanceofNumber);assert(!(123instanceofObject));assert(!(objinstanceofNumber));assert(Object.prototype.toString.call(date)==='[object Date]');assert(Object.prototype.toString.call(date)==='[object Date]');assert(Object.prototype.toString.call(obj)!=='[object Date]');assert(Object.prototype.toString.call(obj)!=='[object Date]');});});

About

A tool to help you migrating from should to assert

Resources

Stars

13 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages