wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
64 lines • 2.86 kB
JavaScript
;
/* global describe it expect */
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var function_to_string_1 = tslib_1.__importDefault(require("./function-to-string"));
describe('functionToString', function () {
describe('given function as argument', function () {
it('should convert to arrow function and return it', function () {
/* tslint:disable */
function prop(arg) {
return 'value' + arg;
}
/* tslint:enable */
expect((0, function_to_string_1.default)(prop)).toEqual("arg => 'value' + arg");
});
it('should handle multiple arguments', function () {
/* tslint:disable */
function prop(arg1, arg2, arg3) {
var anything = 'hello';
return arg1 + arg2 + arg3 + anything;
}
/* tslint:enable */
expect((0, function_to_string_1.default)(prop)).toEqual("(arg1, arg2, arg3) => {\n var anything = 'hello';\n return arg1 + arg2 + arg3 + anything;\n}");
});
it('should not do anything to arrow function', function () {
/* tslint:disable */
var prop = function (arg) { return arg + 1; };
/* tslint:enable */
expect((0, function_to_string_1.default)(prop)).toEqual("arg => arg + 1");
});
it('should convert properties to shorthand if possible', function () {
/* tslint:disable */
function prop(value) {
// intentional ignore
// @ts-ignore
return setState({
value: value,
});
}
/* tslint:enable */
expect((0, function_to_string_1.default)(prop)).toEqual("value => setState({\n value\n})");
});
it('should work with FunctionExpression', function () {
var obj = {
functionExpression: function (argument1, argument2) {
var rest = [];
for (var _i = 2; _i < arguments.length; _i++) {
rest[_i - 2] = arguments[_i];
}
return 'this is a method';
},
};
expect((0, function_to_string_1.default)(obj.functionExpression)).toEqual(obj.functionExpression.toString());
});
});
describe('given non function argument', function () {
[0, 10, false, String('hello'), [], null, NaN, Infinity].map(function (assert) {
return it("which is ".concat(assert, " should return ").concat(assert), function () {
return expect((0, function_to_string_1.default)(assert)).toEqual(assert);
});
});
});
});
//# sourceMappingURL=function-to-string.test.js.map