安装依赖 package.json
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"babel-jest": "^28.1.0",
"jest": "^28.1.0"
}
配置babel babel.config.js
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
};
测试脚本 os.spec.js
const MACOS_SYstem = 'Darwin'
const isMacOS = () => {
return require('os').type() === MACOS_SYstem
}
describe('os test', () => {
test('Is macOS system', () => {
expect(isMacOS()).toBeTruthy()
});
});