spec/screenplay/questions/mappings/string/toUpperCase.spec.ts
import 'mocha';
import { given } from 'mocha-testdata';
import { actorCalled } from '../../../../../src';
import { Question,toUpperCase } from '../../../../../src/screenplay';
import { expect } from '../../../../expect';
describe('toUpperCase', () => {
const quentin = actorCalled('Quentin');
const q = <T>(value: T) =>
Question.about<T>('some value', actor => value);
const p = <T>(value: T) =>
Promise.resolve(value);
given([
{ value: null, expected: 'The value to be mapped should be defined' },
{ value: undefined, expected: 'The value to be mapped should be defined' },
{ value: 1, expected: 'The value to be mapped should be a string' },
{ value: { }, expected: 'The value to be mapped should be a string' },
{ value: [null], expected: 'The value to be mapped should be defined' },
{ value: [undefined], expected: 'The value to be mapped should be defined' },
{ value: [1], expected: 'The value to be mapped should be a string' },
{ value: [{ }], expected: 'The value to be mapped should be a string' },
{ value: p(null), expected: 'The value to be mapped should be defined' },
{ value: p(undefined), expected: 'The value to be mapped should be defined' },
{ value: p(1), expected: 'The value to be mapped should be a string' },
{ value: p({ }), expected: 'The value to be mapped should be a string' },
{ value: p([ null ]), expected: 'The value to be mapped should be defined' },
{ value: p([ undefined ]), expected: 'The value to be mapped should be defined' },
{ value: p([ 1 ]), expected: 'The value to be mapped should be a string' },
{ value: p([ { } ]), expected: 'The value to be mapped should be a string' },
]).
it('complains if the original answer is of a wrong type at runtime', ({ value, expected }) => {
const result = q<any>(value)
.map(toUpperCase())
.answeredBy(quentin);
return expect(result).to.be.rejectedWith(expected);
});
given([
{ value: 'HeLlO!' },
{ value: p('HeLlO!') },
]).
it('converts the string to lower case', ({ value }) => {
const result = q(value)
.map(toUpperCase())
.answeredBy(quentin);
return expect(result).to.be.eventually.equal('HELLO!');
});
});