wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
114 lines • 4.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var drivers_1 = require("./drivers");
describe('MethodDocumentation', function () {
var driver = (0, drivers_1.createMethodDocumentationDriver)();
var method = {
name: 'method',
type: 'function',
args: [
{
name: 'param1',
type: 'string',
},
],
};
it('has a function name', function () {
driver.create({ unit: method });
expect(driver.get.name()).toBe('method');
});
describe('no arguments', function () {
beforeEach(function () {
driver.create({
unit: tslib_1.__assign(tslib_1.__assign({}, method), { args: [] }),
});
});
it("has an empty string", function () {
expect(driver.get.arguments()).toBe('');
});
});
describe('arguments', function () {
describe('with types', function () {
describe('one', function () {
beforeEach(function () {
driver.create({ unit: method });
});
it('has name', function () {
expect(driver.get.argumentNames()[0]).toBe('param1');
});
it('has type', function () {
expect(driver.get.argumentTypes()[0]).toBe(': string');
});
});
describe('multiple', function () {
var unit = tslib_1.__assign(tslib_1.__assign({}, method), { args: [
{ name: 'str1', type: 'string' },
{ name: 'str2', type: 'string' },
] });
beforeEach(function () {
driver.create({ unit: unit });
});
it('has a list of arguments', function () {
expect(driver.get.argumentNames().length).toBe(2);
});
it('has names', function () {
var names = driver.get.argumentNames();
expect(names.length).toBe(unit.args.length);
unit.args.forEach(function (argument, index) {
expect(names[index]).toBe(argument.name);
});
});
it('has types', function () {
var types = driver.get.argumentTypes();
expect(types.length).toBe(unit.args.length);
unit.args.forEach(function (argument, index) {
expect(types[index]).toBe(": ".concat(argument.type));
});
});
it('are comma separated', function () {
var args = driver.get.arguments();
expect(args).toBe('str1: string, str2: string');
});
});
});
describe('without types', function () {
beforeEach(function () {
driver.create({
unit: tslib_1.__assign(tslib_1.__assign({}, method), { args: [
{
name: 'str1',
},
{
name: 'str2',
},
] }),
});
});
it('has arguments names', function () {
expect(driver.get.argumentNames().length).toBe(2);
});
it("doesn't render argument types", function () {
expect(driver.get.argumentTypes().length).toBe(0);
});
it('are comma separated', function () {
var args = driver.get.arguments();
expect(args).toBe('str1, str2');
});
});
});
describe('description', function () {
it('can have a description', function () {
var description = 'some description';
driver.create({
unit: tslib_1.__assign(tslib_1.__assign({}, method), { description: description }),
});
expect(driver.get.description()).toBe(description);
});
it('renders empty cell when theres no description', function () {
driver.create({ unit: method });
expect(driver.get.description()).toBe('');
});
});
});
//# sourceMappingURL=method-documentation.test.js.map