-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
308 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import chai from 'chai'; | ||
import sinon from 'sinon'; | ||
import Console from '../../lib/extend/console'; | ||
chai.should(); | ||
|
||
describe('console', () => { | ||
it('register - name required', () => { | ||
const consoleExtend = new Console(); | ||
try { | ||
// @ts-expect-error | ||
consoleExtend.register(); | ||
} catch (err) { | ||
err.should.have.property('message', 'name is required'); | ||
} | ||
}); | ||
|
||
it('register - name, invalid fn', () => { | ||
const consoleExtend = new Console(); | ||
try { | ||
// @ts-expect-error | ||
consoleExtend.register('test', 'fn'); | ||
} catch (err) { | ||
err.should.have.property('message', 'fn must be a function'); | ||
} | ||
}); | ||
|
||
it('register - name, desc, invalid fn', () => { | ||
const consoleExtend = new Console(); | ||
try { | ||
// @ts-expect-error | ||
consoleExtend.register('test', 'desc', 'fn'); | ||
} catch (err) { | ||
err.should.have.property('message', 'fn must be a function'); | ||
} | ||
}); | ||
|
||
it('register - name, options, fn', () => { | ||
const consoleExtend = new Console(); | ||
const options = {}; | ||
const fn = sinon.spy(); | ||
consoleExtend.register('test', options, fn); | ||
const storeFn = consoleExtend.get('test'); | ||
storeFn(); | ||
fn.calledOnce.should.be.true; | ||
storeFn.options?.should.eql(options); | ||
storeFn.desc?.should.eql(''); | ||
}); | ||
|
||
it('register - name, desc, fn', () => { | ||
const consoleExtend = new Console(); | ||
const desc = 'desc'; | ||
const fn = sinon.spy(); | ||
consoleExtend.register('test', desc, fn); | ||
const storeFn = consoleExtend.get('test'); | ||
storeFn(); | ||
fn.calledOnce.should.be.true; | ||
storeFn.options?.should.deep.equal({}); | ||
storeFn.desc?.should.eql(desc); | ||
}); | ||
|
||
it('register - name, fn', () => { | ||
const consoleExtend = new Console(); | ||
const fn = sinon.spy(); | ||
consoleExtend.register('test', fn); | ||
const storeFn = consoleExtend.get('test'); | ||
storeFn(); | ||
fn.calledOnce.should.be.true; | ||
storeFn.options?.should.deep.equal({}); | ||
storeFn.desc?.should.eql(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters