Skip to content

Commit

Permalink
test: woof command language selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Avishag Israeli authored and JackuB committed Oct 5, 2020
1 parent 8016ae2 commit c5432cd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cli/commands/woof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const woofs = {
cs: ' Haf!',
};

export = function woof(...args: MethodArgs) {
export function getWoofLanguage(args: MethodArgs): string {
const options = args.pop() as ArgsOptions;
let lang = 'en';

Expand All @@ -18,6 +18,12 @@ export = function woof(...args: MethodArgs) {
) {
lang = options.language;
}

return lang;
}

export default function woof(...args: MethodArgs) {
const lang = getWoofLanguage(args);
console.log(`
| |
/| |\\
Expand All @@ -34,4 +40,4 @@ export = function woof(...args: MethodArgs) {
\\U/ --( ${woofs[lang]} )
\\-----/
`);
};
}
28 changes: 28 additions & 0 deletions test/woof.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getWoofLanguage } from '../src/cli/commands/woof';

describe('Woof command - Language option', () => {
it('Default language is "en"', () => {
// $ snyk woof
expect(getWoofLanguage([{} as any])).toEqual('en');
});

it('Returns selected language', () => {
expect(
getWoofLanguage([
{
language: 'he',
} as any,
]),
).toEqual('he');
});

it('Returns default when selected language is invalid', () => {
expect(
getWoofLanguage([
{
language: 'toString',
} as any,
]),
).toEqual('en');
});
});

0 comments on commit c5432cd

Please sign in to comment.