test/string.test.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 1

Size

Lines of Code 87
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
nc 1
dl 0
loc 87
c 1
b 0
f 0
cc 0
rs 10
noi 0
wmc 10
mnd 0
bc 10
fnc 10
bpm 1
cpm 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A string.test.js ➔ ??? 0 6 1
1
"use strict";
2
const JString = require("../src/types/string");
3
4
test("test instantiation of JString", () => {
5
    const string = new JString();
6
7
    expect(string).toBeInstanceOf(JString);
8
    expect(string.type).toBe("string");
9
});
10
11
test("test email()", () => {
12
    const string = new JString();
13
14
    expect(string.email()).toBe(string);
15
    expect(string.isEmail).toBeTruthy();
16
});
17
18
test("test alphanum()", () => {
19
    const string = new JString();
20
21
    expect(string.alphanum()).toBe(string);
22
    expect(string.isAlphanum).toBeTruthy();
23
});
24
25
describe("test JString.validate()", () => {
26
    test("test non strict", () => {
27
        const string = new JString();
28
        const data = { test: "" };
29
30
        expect(string.validate(data, "test")).toBeNull();
31
    });
32
33
    test("test strict", () => {
34
        const string = new JString(true);
35
        const data = { test: 5 };
36
37
        expect(string.validate(data, "test")).toEqual({ error: {
38
            type: "JString:strict",
39
            field: "test",
40
            message: "'test' is not the correct type."
41
        }});
42
    });
43
44
    test("test minValue", () => {
45
        const string = new JString().min(5);
46
        const data = { test: "test" };
47
48
        expect(string.validate(data, "test")).toEqual({ error: {
49
            type: "JString:min",
50
            field: "test",
51
            message: "'test' has a minimum required length of '5'."
52
        }});
53
    });
54
55
    test("test maxValue", () => {
56
        const string = new JString().max(3);
57
        const data = { test: "test" };
58
59
        expect(string.validate(data, "test")).toEqual({ error: {
60
            type: "JString:max",
61
            field: "test",
62
            message: "'test' has a maximum length of '3'."
63
        }});
64
    });
65
66
    test("test email", () => {
67
        const string = new JString().email();
68
        const data = { test: "test" };
69
70
        expect(string.validate(data, "test")).toEqual({ error: {
71
            type: "JString:email",
72
            field: "test",
73
            message: "'test' needs to be a valid email."
74
        }});
75
    });
76
77
    test("test alphanum", () => {
78
        const string = new JString().alphanum();
79
        const data = { test: "test()" };
80
81
        expect(string.validate(data, "test")).toEqual({ error: {
82
            type: "JString:alphanum",
83
            field: "test",
84
            message: "'test' only accepts alphanumeric characters."
85
        }});
86
    });
87
});
88