Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [BREAKING] don't allow to mock async function to normal function (
#46) drop node support 4, 6, now support node version >= 8
- Loading branch information
Showing
7 changed files
with
156 additions
and
86 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
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
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,52 @@ | ||
'use strict'; | ||
|
||
const mm = require('..'); | ||
|
||
describe('test/async-await.test.js', () => { | ||
const foo = { | ||
async request() { | ||
return 'yes'; | ||
}, | ||
}; | ||
|
||
afterEach(mm.restore); | ||
|
||
describe('mm()', () => { | ||
it('should mock async function', async () => { | ||
let datas; | ||
mm(foo, 'request', async () => { | ||
return 'no'; | ||
}); | ||
datas = await foo.request(); | ||
datas.should.equal('no'); | ||
|
||
mm.restore(); | ||
datas = await foo.request(); | ||
datas.should.equal('yes'); | ||
}); | ||
|
||
it('should mock async function to normal throw type error', async () => { | ||
try { | ||
mm(foo, 'request', () => { | ||
return 'no'; | ||
}); | ||
throw new Error('should not run this'); | ||
} catch (err) { | ||
err.message.should.equal('Can\'t mock async function to normal function'); | ||
} | ||
}); | ||
}); | ||
|
||
describe('datas(), data()', () => { | ||
it('should mock async function', async () => { | ||
let datas; | ||
mm.datas(foo, 'request', 'no'); | ||
datas = await foo.request(); | ||
datas.should.equal('no'); | ||
|
||
mm.restore(); | ||
datas = await foo.request(); | ||
datas.should.equal('yes'); | ||
}); | ||
}); | ||
}); |
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