smartcli/test/test.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

import { tap, expect } from '@pushrocks/tapbundle';
import { Subject } from 'rxjs';
2016-06-10 00:27:04 +00:00
2022-08-03 15:00:36 +00:00
import * as smartcli from '../ts/index.js';
2017-04-22 19:03:28 +00:00
let smartCliTestObject: smartcli.Smartcli;
2017-04-22 19:03:28 +00:00
tap.test('should create a new Smartcli', async () => {
smartCliTestObject = new smartcli.Smartcli();
2022-08-03 15:00:36 +00:00
expect(smartCliTestObject).toBeInstanceOf(smartcli.Smartcli);
});
2017-04-22 19:03:28 +00:00
tap.test('should add an command', async () => {
2022-08-03 15:00:36 +00:00
expect(smartCliTestObject.addCommand('awesome')).toBeInstanceOf(Subject);
});
2017-04-22 19:03:28 +00:00
tap.test('should start parsing a standardTask', async () => {
2022-08-03 15:00:36 +00:00
expect(smartCliTestObject.standardCommand()).toBeInstanceOf(Subject);
});
2017-04-22 19:03:28 +00:00
let hasExecuted: boolean = false;
2017-04-22 19:03:28 +00:00
tap.test('should accept a command', async () => {
2022-08-03 15:00:36 +00:00
smartCliTestObject.addCommand('triggerme').subscribe(() => {
hasExecuted = true;
});
});
2017-04-22 20:09:51 +00:00
2017-04-22 19:03:28 +00:00
tap.test('should not have executed yet', async () => {
2022-08-03 15:00:36 +00:00
expect(hasExecuted).toBeFalse();
});
2017-04-22 20:09:51 +00:00
2017-04-22 19:03:28 +00:00
tap.test('should execute when triggered', async () => {
2022-08-03 15:00:36 +00:00
smartCliTestObject.triggerCommand('triggerme', {});
expect(hasExecuted).toBeTrue();
});
2017-04-22 19:03:28 +00:00
2017-04-23 13:21:08 +00:00
tap.test('should start parsing the CLI input', async () => {
smartCliTestObject.startParse();
2022-08-03 15:00:36 +00:00
expect(smartCliTestObject.parseCompleted.promise).toBeInstanceOf(Promise);
});
2017-04-23 13:21:08 +00:00
tap.start();