-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.js
168 lines (127 loc) · 4.39 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const Chance = require('chance');
const pathObject = require('./index');
describe('index', () => {
const chance = new Chance();
let chanceD6, chancePath, chanceWord;
beforeEach(() => {
chance.mixin({
pathObject
});
chanceD6 = chance.d6();
chanceWord = chance.word();
spyOn(Chance.prototype, 'd6').and.returnValue(chanceD6);
spyOn(Chance.prototype, 'word').and.returnValue(chanceWord);
chancePath = chance.n(chance.word, chance.d6()).join('/');
});
describe('root', () => {
test('should return an empty string by default', () => {
const result = chance.pathObject();
expect(result.root).toBe('');
});
test('should return when specified', () => {
const result = chance.pathObject({
root: true
});
expect(result.root).toBe('/');
});
});
describe('dir', () => {
test('should return an empty string by default', () => {
const result = chance.pathObject();
expect(result.dir).toBe('');
});
test('should return when specified', () => {
const result = chance.pathObject({
dir: true
});
expect(result.dir).toBe(chancePath);
});
test('should return with root prepended when specified', () => {
const result = chance.pathObject({
dir: true,
root: true
});
expect(result.dir).toBe(`/${chancePath}`);
});
test('should return with relative directory prepended when specified', () => {
const result = chance.pathObject({
dir: true,
relative: true
});
expect(result.dir).toBe(`../${chancePath}`);
});
test('should return with root prepended when both root and relative are specified', () => {
const result = chance.pathObject({
dir: true,
relative: true,
root: true
});
expect(result.dir).toBe(`/${chancePath}`);
});
});
describe('name', () => {
test('should return an empty string by default', () => {
const result = chance.pathObject();
expect(result.name).toBe('');
});
test('should return when specified', () => {
const result = chance.pathObject({
name: true
});
expect(result.name).toBe(chanceWord);
});
test('should return as dotfile when specified', () => {
const result = chance.pathObject({
dotfile: true,
name: true
});
expect(result.name).toBe(`.${chanceWord}`);
});
});
describe('ext', () => {
test('should return an empty string by default', () => {
const result = chance.pathObject();
expect(result.ext).toBe('');
});
test('should return when specified', () => {
const result = chance.pathObject({
ext: true
});
expect(result.ext).toBe(`.${chanceWord}`);
});
});
describe('base', () => {
test('should return an empty string by default', () => {
const result = chance.pathObject();
expect(result.base).toBe('');
});
test('should return when specified', () => {
const result = chance.pathObject({
base: true
});
expect(result.base).toBe(`${chanceWord}.${chanceWord}`);
});
test('should return name when specified', () => {
const result = chance.pathObject({
base: true,
name: true
});
expect(result.base).toBe(result.name);
});
test('should return ext when specified', () => {
const result = chance.pathObject({
base: true,
ext: true
});
expect(result.base).toBe(result.ext);
});
test('should return name and ext when specified', () => {
const result = chance.pathObject({
base: true,
ext: true,
name: true
});
expect(result.base).toBe(result.name + result.ext);
});
});
});