Completed
Push — master ( 8c53f9...1d869a )
by Marcelo
33s
created

test/input.spec.js   A

Complexity

Total Complexity 9
Complexity/F 1

Size

Lines of Code 37
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 9
c 1
b 0
f 0
nc 1
mnd 0
bc 8
fnc 9
dl 0
loc 37
rs 10
bpm 0.8888
cpm 1
noi 1
1
import { expect } from 'chai';
2
import intercept from 'intercept-stdout';
3
import { IO, resolveValue, triggerWarnings } from '../src/input';
4
import { String as Text } from '../src/types';
5
import { compileES6 } from '../src/compiler';
6
7
describe('input.js', () => {
8
    describe('Value parsing', () => {
9
        it('should get a simple string', () => {
10
            const value = resolveValue('test', Text, null, true);
11
            expect(value).to.equals('test');
12
        });
13
14
        it('should return null for a required string', () => {
15
            const value = resolveValue('', Text, null, true);
16
            expect(value).to.be.null;
17
        });
18
19
        it('should accept the default value of a string', () => {
20
            const value = resolveValue('', Text, 'alaska', false);
21
            expect(value).to.equals('alaska');
22
        });
23
    });
24
25
    describe('Warnings', () => {
26
        it('should trigger a warning when has named parameter language', () => {
27
            let result = '';
28
            const stopReading = intercept(text => result += text);
29
            const io = IO();
30
            triggerWarnings(io, { language: {} })
31
                .then(() => {
32
                    stopReading();
33
                    expect(result).to.match(/Warning: don't use context.params.language/);
34
                });
35
        });
36
    });
37
});