经过一番研究,我找到了一个与我正在寻找的选项一致的选项。
摩卡
这是受 MaterialUI 存储库的启发,它使用 mocha 和 chai:
import { expect } from 'chai';
import * as MyLib from './index';
describe('MyLib', () => {
it('should have exports', () => {
expect(typeof MyLib).to.equal('object');
});
it('should not have undefined exports', () => {
Object.keys(MyLib).forEach((exportKey) =>
expect(Boolean(MyLib[exportKey])).to.equal(true),
);
});
});
来源:https://github.com/mui-org/material-ui/blob/next/packages/material-ui/src/index.test.js
开玩笑
当我们在我的项目中使用 JEST 时,我们必须对其进行转换:
import * as MyLib from './index';
describe('MyLib', () => {
it('should have exports', () => {
expect(typeof MyLib).toBe('object');
});
it('should not have undefined exports', () => {
Object.keys(MyLib).forEach((exportKey) =>
expect(Boolean(MyLib[exportKey])).toBe(true),
);
});
});