我想知道如何为npm包Inquirer.js编写单元测试,这是使CLI包更容易使用的工具。我已经阅读了这篇文章,但无法使其正常工作。
这是我的代码,需要进行测试:
const questions = [
{
type: 'input',
name: 'email',
message: "What's your email ?",
},
{
type: 'password',
name: 'password',
message: 'Enter your password (it will not be saved neither communicate for other purpose than archiving)'
}
];
inquirer.prompt(questions).then(answers => {
const user = create_user(answers.email, answers.password);
let guessing = guess_unix_login(user);
guessing.then(function (user) {
resolve(user);
}).catch(function (message) {
reject(message);
});
} );
Run Code Online (Sandbox Code Playgroud)
...这是用Mocha编写的测试:
describe('#create_from_stdin', function () {
this.timeout(10000);
check_env(['TEST_EXPECTED_UNIX_LOGIN']);
it('should find the unix_login user and …Run Code Online (Sandbox Code Playgroud) stdin unit-testing command-line-interface node.js inquirerjs