我想测试以下方法但失败了。 "npm ERR! code ELIFECYCLE" "这可能不是 npm 的问题。上面可能有额外的日志输出。"
const co2cal = (tm, d, output) => {
switch (tm) {
case 'small-diesel-car':
if(output === 'g') {
console.log(`Your trip caused ${transportationMethod['small-diesel-car'] * d}g of CO2-equivalent`);
} else {
console.log(`Your trip caused ${(transportationMethod['small-diesel-car'] * d / 1000).toFixed(1)} kg of CO2-equivalent`);
}
break;
case 'small-petrol-car':
if(output === 'g') {
console.log(`Your trip caused ${transportationMethod['small-petrol-car'] * d}g of CO2-equivalent`);
} else {
console.log(`Your trip caused ${(transportationMethod['small-petrol-car'] * d / 1000).toFixed(1)} kg of CO2-equivalent`);
}
break;
default: console.log('No transportation method in this name');
}
};
//Test method Error -- 'Received: undefined'
const testCo2cal = require('./co2cal');
test('should return 2.1', () => {
expect(testCo2cal("small-diesel-car", 15)).toEqual(2.1);
});