測試函數(shù)let sinon = require("sinon");let main = require("../lib/main");describe('main()', () => { it('should display main menu once started', () => { sinon.spy(console, 'log'); main(); expect(console.log.args.join()).toBe(`1. 添加學(xué)生2. 生成成績單3. 退出請輸入你的選擇(1~3):`); }); it('should display 請輸入學(xué)生信息(格式:姓名, 學(xué)號, 民族, 班級, 學(xué)科: 成績, ...)', () => { // sinon.spy(console, 'log'); const display = main(); // console.log(display) expect(display).toBe('請輸入學(xué)生信息(格式:姓名, 學(xué)號, 民族, 班級, 學(xué)科: 成績, ...),按回車提交:') }) });被測函數(shù)module.exports = () => { function choice1(){ let display = '請輸入學(xué)生信息(格式:姓名, 學(xué)號, 民族, 班級, 學(xué)科: 成績, ...),按回車提交:' return display; } function choice2(){ } function choice3(){ } function invalidInput1(){ } function defaultPage(){ console.log( `1. 添加學(xué)生2. 生成成績單3. 退出請輸入你的選擇(1~3):`) } defaultPage(); var readlineSync = require('readline-sync'); var answer = readlineSync.question(); if(answer == 1){ choice1(); }else if(answer == 2){ choice2(); }else if(answer == 3){ choice3(); }else{ return 'Bad choice, please choose again!' }}運(yùn)行結(jié)果
js中的一條測試用例在調(diào)用主函數(shù)時(shí),總是返回undefined
拉風(fēng)的咖菲貓
2019-03-20 18:15:27