@ async-fn/ 欢呼

asyncFn 数据 jest 提供了引入 jest.fn 的补充方法 "迟解" 因为承诺还原.
通过允许按时间顺序读取的测试来简化合成单元测试, 像故事一样,并且不需要过度的测试设置来事先知道在每种情景下,aync mops应该如何表现.
它已经 100%单位测试覆盖率,和3+年的重点 生产用途 高级 开发者满意度。 。 。 .
asyncFn 也为 综合测试 用于组合最近的OS-,节点-和嘲笑的框架-版本.
如何安装
$ npm install --save-dev @async-fn/jest
教学
参见教程 这里。 。 。 .
实例
迟到的发号施令 将测试看成故事
import asyncFn from '@async-fn/jest';
it('given called, a result can be resolved *after* the mock is called', async () => {
const mockFunction = asyncFn();
const promise = mockFunction();
// Note how we resolve the returned promise *after* it is called.
// This permits us to write our tests so that they read like a story.
await mockFunction.resolve('some-value');
const actual = await promise;
expect(actual).toBe('some-value');
});
迟到下定决心,多次呼吁嘲弄
import asyncFn from '@async-fn/jest';
it('given called multiple times, the results can be resolved *after* the mock was called', async () => {
const mockFunction = asyncFn();
const promise = Promise.all([mockFunction(), mockFunction(), mockFunction()]);
await mockFunction.resolve('some-first-value');
await mockFunction.resolve('some-second-value');
await mockFunction.resolve('some-third-value');
const actual = await promise;
expect(actual).toEqual([
'some-first-value',
'some-second-value',
'some-third-value',
]);
});
等待解决的电话的巧合
import asyncFn from '@async-fn/jest';
it('can be awaited to test the coincidences of resolve', async () => {
const mockFunction = asyncFn();
let coincidenceHasHappened = false;
mockFunction()
.then()
.then()
.then(() => {
coincidenceHasHappened = true;
});
await mockFunction.resolve();
expect(coincidenceHasHappened).toBe(true);
});
逾期拒绝
import asyncFn from '@async-fn/jest';
it('can be rejected with a rejection', () => {
const mockFunction = asyncFn();
const promise = mockFunction();
mockFunction.reject('some-rejection');
return expect(promise).rejects.toBe('some-rejection');
});
其他的笑话,fn做
import asyncFn from '@async-fn/jest';
it('does what jest.fn does', () => {
const mockFunction = asyncFn();
mockFunction('some-argument', 'some-other-argument');
expect(mockFunction).toHaveBeenCalledWith(
'some-argument',
'some-other-argument',
);
});
更多实例
看看这个 单位测试。 。 。 .
可用性
目前AsyncFn也可用于 鼻涕虫。 。 。 .
我们是谁?
asyncFn 被你的朋友精心设计 团队: Igniter 来自 休斯敦咨询公司。 。 。 .
我们是软件开发团队 朋友们具有经证明的职业优秀传统。 我们专门从事整体的快速部署,而不牺牲质量.