Skip to content
Permalink
Browse files
fix(core): make sure Question.isAQuestion works with any invalid valu…
…es that might be thrown at it
  • Loading branch information
jan-molak committed Sep 23, 2020
1 parent 599a782 commit 2d6bf91405ad464237010bf2f1dc409a36fcb87d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
@@ -1,4 +1,5 @@
import 'mocha';
import { given } from 'mocha-testdata';

import { actorCalled, AnswersQuestions } from '../../src';
import { Mappable } from '../../src/io';
@@ -149,4 +150,18 @@ describe('Question', () => {
return expect(endResult).to.eventually.deep.equal([6.67, 3.34]);
});
});

given([
{ isAQuestion: false, value: null },
{ isAQuestion: false, value: false },
{ isAQuestion: false, value: void 0 },
{ isAQuestion: false, value: '' },
{ isAQuestion: false, value: {} },
{ isAQuestion: false, value: 42 },
{ isAQuestion: false, value: () => void 0 },
{ isAQuestion: true, value: Question.about('something', actor => void 0) },
]).
it('recognises if something is a question', ({ value, isAQuestion }) => {
expect(Question.isAQuestion(value)).to.equal(isAQuestion);
});
});
@@ -93,7 +93,7 @@ export abstract class Question<T> {
* @returns {boolean}
*/
static isAQuestion<T>(maybeQuestion: any): maybeQuestion is Question<T> {
return !! (maybeQuestion as any).answeredBy;
return !! maybeQuestion && !! (maybeQuestion as any).answeredBy;
}

/**

0 comments on commit 2d6bf91

Please sign in to comment.