@storybook/csf 0.0.2--canary.92ac0db.0 → 0.0.2--canary.7c6c115.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -19,9 +19,10 @@ var testValue = function testValue(cond, value) {
|
|
19
19
|
var _ref = cond,
|
20
20
|
exists = _ref.exists,
|
21
21
|
eq = _ref.eq,
|
22
|
-
neq = _ref.neq
|
22
|
+
neq = _ref.neq,
|
23
|
+
truthy = _ref.truthy;
|
23
24
|
|
24
|
-
if (count([exists, eq, neq]) > 1) {
|
25
|
+
if (count([exists, eq, neq, truthy]) > 1) {
|
25
26
|
throw new Error("Invalid conditional test ".concat(JSON.stringify({
|
26
27
|
exists: exists,
|
27
28
|
eq: eq,
|
@@ -40,10 +41,10 @@ var testValue = function testValue(cond, value) {
|
|
40
41
|
if (typeof exists !== 'undefined') {
|
41
42
|
var valueExists = typeof value !== 'undefined';
|
42
43
|
return exists ? valueExists : !valueExists;
|
43
|
-
}
|
44
|
-
|
44
|
+
}
|
45
45
|
|
46
|
-
|
46
|
+
var shouldBeTruthy = typeof truthy === 'undefined' ? true : truthy;
|
47
|
+
return shouldBeTruthy ? !!value : !value;
|
47
48
|
};
|
48
49
|
/**
|
49
50
|
* Helper function to include/exclude an arg based on the value of other other args
|
@@ -4,8 +4,20 @@ var _includeConditionalArg = require("./includeConditionalArg");
|
|
4
4
|
|
5
5
|
/* eslint-disable @typescript-eslint/ban-ts-ignore */
|
6
6
|
describe('testValue', function () {
|
7
|
-
describe('
|
8
|
-
it.each([['implicit true', {}, true, true], ['implicit truthy', {}, 1, true], ['implicit
|
7
|
+
describe('truthy', function () {
|
8
|
+
it.each([['implicit true', {}, true, true], ['implicit truthy', {}, 1, true], ['implicit falsey', {}, 0, false], ['truthy true', {
|
9
|
+
truthy: true
|
10
|
+
}, true, true], ['truthy truthy', {
|
11
|
+
truthy: true
|
12
|
+
}, 1, true], ['truthy falsey', {
|
13
|
+
truthy: true
|
14
|
+
}, 0, false], ['falsey true', {
|
15
|
+
truthy: false
|
16
|
+
}, true, false], ['falsey truthy', {
|
17
|
+
truthy: false
|
18
|
+
}, 1, false], ['falsey falsey', {
|
19
|
+
truthy: false
|
20
|
+
}, 0, true]])('%s', function (_name, cond, value, expected) {
|
9
21
|
// @ts-ignore
|
10
22
|
expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
|
11
23
|
});
|
@@ -127,40 +139,32 @@ describe('includeConditionalArg', function () {
|
|
127
139
|
}
|
128
140
|
}, {
|
129
141
|
a: 1
|
130
|
-
}, {}, true], ['
|
142
|
+
}, {}, true], ['truthy true', {
|
131
143
|
"if": {
|
132
|
-
arg: 'a'
|
144
|
+
arg: 'a',
|
145
|
+
truthy: true
|
133
146
|
}
|
134
147
|
}, {
|
135
148
|
a: 0
|
136
|
-
}, {}, false], ['
|
149
|
+
}, {}, false], ['truthy false', {
|
137
150
|
"if": {
|
138
|
-
arg: 'a'
|
151
|
+
arg: 'a',
|
152
|
+
truthy: false
|
139
153
|
}
|
140
|
-
}, {}, {},
|
154
|
+
}, {}, {}, true]])('%s', function (_name, argType, args, globals, expected) {
|
141
155
|
// @ts-ignore
|
142
156
|
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
143
157
|
});
|
144
158
|
});
|
145
159
|
describe('exists', function () {
|
146
|
-
it.each([['
|
147
|
-
"if": {
|
148
|
-
arg: 'a'
|
149
|
-
}
|
150
|
-
}, {
|
151
|
-
a: 1
|
152
|
-
}, {}, true], ['implicit exist false', {
|
153
|
-
"if": {
|
154
|
-
arg: 'a'
|
155
|
-
}
|
156
|
-
}, {}, {}, false], ['explicit exist', {
|
160
|
+
it.each([['exist', {
|
157
161
|
"if": {
|
158
162
|
arg: 'a',
|
159
163
|
exists: true
|
160
164
|
}
|
161
165
|
}, {
|
162
166
|
a: 1
|
163
|
-
}, {}, true], ['
|
167
|
+
}, {}, true], ['exist false', {
|
164
168
|
"if": {
|
165
169
|
arg: 'a',
|
166
170
|
exists: true
|
@@ -216,24 +220,32 @@ describe('includeConditionalArg', function () {
|
|
216
220
|
});
|
217
221
|
});
|
218
222
|
describe('globals', function () {
|
219
|
-
describe('
|
223
|
+
describe('truthy', function () {
|
220
224
|
it.each([['implicit true', {
|
221
225
|
"if": {
|
222
226
|
global: 'a'
|
223
227
|
}
|
224
228
|
}, {}, {
|
225
229
|
a: 1
|
226
|
-
}, true], ['implicit
|
230
|
+
}, true], ['implicit undefined', {
|
227
231
|
"if": {
|
228
232
|
global: 'a'
|
229
233
|
}
|
234
|
+
}, {}, {}, false], ['truthy true', {
|
235
|
+
"if": {
|
236
|
+
global: 'a',
|
237
|
+
truthy: true
|
238
|
+
}
|
230
239
|
}, {}, {
|
231
240
|
a: 0
|
232
|
-
}, false], ['
|
241
|
+
}, false], ['truthy false', {
|
233
242
|
"if": {
|
234
|
-
global: 'a'
|
243
|
+
global: 'a',
|
244
|
+
truthy: false
|
235
245
|
}
|
236
|
-
}, {}, {
|
246
|
+
}, {}, {
|
247
|
+
a: 0
|
248
|
+
}, true]])('%s', function (_name, argType, args, globals, expected) {
|
237
249
|
// @ts-ignore
|
238
250
|
expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
|
239
251
|
});
|
package/dist/story.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/csf",
|
3
|
-
"version": "0.0.2--canary.
|
3
|
+
"version": "0.0.2--canary.7c6c115.0",
|
4
4
|
"description": "Component Story Format (CSF) utilities",
|
5
5
|
"keywords": [
|
6
6
|
"storybook",
|
@@ -38,7 +38,10 @@
|
|
38
38
|
},
|
39
39
|
"prettier": "@storybook/linter-config/prettier.config",
|
40
40
|
"jest": {
|
41
|
-
"testEnvironment": "node"
|
41
|
+
"testEnvironment": "node",
|
42
|
+
"roots": [
|
43
|
+
"<rootDir>/src"
|
44
|
+
]
|
42
45
|
},
|
43
46
|
"dependencies": {
|
44
47
|
"lodash": "^4.17.15"
|