1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
const {
Confirm,
List,
Input,
// eslint-disable-next-line node/no-missing-require
} = require("../../../packages/generators/src/utils/scaffold-utils");
describe("utils", () => {
let mockSelf;
beforeEach(() => {
mockSelf = {
prompt: (arg) => {
return arg[0];
},
};
});
describe("Inquirer", () => {
it("should emulate a prompt for List", () => {
expect(List(mockSelf, "entry", "does it work?", ["Yes", "Maybe"], "Yes")).toEqual({
choices: ["Yes", "Maybe"],
type: "list",
name: "entry",
message: "does it work?",
default: "Yes",
});
});
it("should make default value for a List", () => {
expect(List(mockSelf, "entry", "does it work?", ["Yes", "Maybe"], "Yes", true)).toEqual({
entry: "Yes",
});
});
it("should emulate a prompt for list input", () => {
expect(Input(mockSelf, "plugins", "what is your plugin?", "openJSF")).toEqual({
type: "input",
name: "plugins",
message: "what is your plugin?",
default: "openJSF",
});
});
it("should return a default Input object value", () => {
expect(Input(mockSelf, "plugins", "what is your plugin?", "my-plugin", true)).toEqual({
plugins: "my-plugin",
});
});
it("should emulate a prompt for confirm", () => {
expect(Confirm(mockSelf, "context", "what is your context?")).toEqual({
name: "context",
default: true,
message: "what is your context?",
type: "confirm",
});
});
it("should make a Confirm object with yes as default", () => {
expect(Confirm(mockSelf, "context", "what is your context?", true, true)).toEqual({
context: true,
});
});
});
});
|