How to use lastStatement method in storybook-root

Best JavaScript code snippet using storybook-root

componentDocblockHandler-test.ts

Source:componentDocblockHandler-test.ts Github

copy

Full Screen

...5import { NodePath } from 'ast-types/lib/node-path';6jest.mock('../../Documentation');7describe('componentDocblockHandler', () => {8 let documentation: Documentation & DocumentationMock;9 function lastStatement(src: string): NodePath {10 const programPath = parse(src);11 return programPath.get('body', programPath.node.body.length - 1);12 }13 function beforeLastStatement(src: string): NodePath {14 const programPath = parse(src);15 return programPath.get('body', programPath.node.body.length - 2);16 }17 beforeEach(() => {18 documentation = new Documentation() as Documentation & DocumentationMock;19 });20 function test(definitionSrc: string, parseFunc: (src: string) => NodePath) {21 it('finds docblocks for component definitions', () => {22 const definition = parseFunc(`23 import something from 'somewhere';24 /**25 * Component description26 */27 ${definitionSrc}28 `);29 componentDocblockHandler(documentation, definition, noopImporter);30 expect(documentation.description).toBe('Component description');31 });32 it('ignores other types of comments', () => {33 let definition = parseFunc(`34 import something from 'somewhere';35 /*36 * This is not a docblock',37 */38 ${definitionSrc}39 `);40 componentDocblockHandler(documentation, definition, noopImporter);41 expect(documentation.description).toBe('');42 definition = parseFunc(`43 // Inline comment'44 ${definitionSrc}45 `);46 componentDocblockHandler(documentation, definition, noopImporter);47 expect(documentation.description).toBe('');48 });49 it('only considers the docblock directly above the definition', () => {50 const definition = parseFunc(`51 import something from 'somewhere';52 /**53 * This is the wrong docblock54 */55 var something_else = "foo";56 ${definitionSrc}57 `);58 componentDocblockHandler(documentation, definition, noopImporter);59 expect(documentation.description).toBe('');60 });61 }62 /**63 * Decorates can only be assigned to class and therefore only make sense for64 * class declarations and export declarations.65 */66 function testDecorators(classSrc, parseFunc, exportSrc = '') {67 describe('decorators', () => {68 it("uses the docblock above the decorator if it's the only one", () => {69 const definition = parseFunc(`70 import something from 'somewhere';71 /**72 * Component description73 */74 ${exportSrc}75 @Decorator176 @Decorator277 ${classSrc}78 `);79 componentDocblockHandler(documentation, definition, noopImporter);80 expect(documentation.description).toBe('Component description');81 });82 it('uses the component docblock if present', () => {83 const definition = parseFunc(`84 import something from 'somewhere';85 ${exportSrc}86 /**87 * Decorator description88 */89 @Decorator190 @Decorator291 /**92 * Component description93 */94 ${classSrc}95 `);96 componentDocblockHandler(documentation, definition, noopImporter);97 expect(documentation.description).toBe('Component description');98 });99 });100 }101 function testImports(exportSrc, parseFunc, importName, useDefault = false) {102 const importDef = useDefault ? `${importName}` : `{ ${importName} }`;103 const mockImporter = makeMockImporter({104 test1: parseFunc(`105 /**106 * Component description107 */108 ${exportSrc}109 `),110 test2: lastStatement(`111 import ${importDef} from 'test1';112 export default ${importName};113 `).get('declaration'),114 });115 describe('imports', () => {116 it('can use a custom importer to resolve docblocks on imported components', () => {117 const program = lastStatement(`118 import ${importDef} from 'test1';119 export default ${importName};120 `).get('declaration');121 componentDocblockHandler(documentation, program, mockImporter);122 expect(documentation.description).toBe('Component description');123 });124 });125 it('traverses multiple imports', () => {126 const program = lastStatement(`127 import ${importDef} from 'test2';128 export default ${importName};129 `).get('declaration');130 componentDocblockHandler(documentation, program, mockImporter);131 expect(documentation.description).toBe('Component description');132 });133 }134 describe('React.createClass', () => {135 test('var Component = React.createClass({})', src =>136 lastStatement(src).get('declarations', 0, 'init', 'arguments', 0));137 testImports(138 'export var Component = React.createClass({})',139 src => lastStatement(src).get('declaration'),140 'Component',141 );142 });143 describe('ClassDeclaration', () => {144 test('class Component {}', src => lastStatement(src));145 testDecorators('class Component {}', src => lastStatement(src));146 testImports(147 'export class Component {}',148 src => lastStatement(src).get('declaration'),149 'Component',150 );151 });152 describe('ClassExpression', () => {153 test('var Component = class {};', src =>154 lastStatement(src).get('declarations', 0, 'init'));155 testImports(156 'export var Component = class {};',157 src => lastStatement(src).get('declaration'),158 'Component',159 );160 });161 describe('Stateless functions', () => {162 test('function Component() {}', src => lastStatement(src));163 testImports(164 'export function Component() {}',165 src => lastStatement(src).get('declaration'),166 'Component',167 );168 test('var Component = function () {};', src =>169 lastStatement(src).get('declarations', 0, 'init'));170 testImports(171 'export var Component = function () {};',172 src => lastStatement(src).get('declaration'),173 'Component',174 );175 test('var Component = () => {}', src =>176 lastStatement(src).get('declarations', 0, 'init'));177 testImports(178 'export var Component = () => {}',179 src => lastStatement(src).get('declaration'),180 'Component',181 );182 });183 describe('ES6 default exports', () => {184 describe('Default React.createClass export', () => {185 test('export default React.createClass({});', src =>186 lastStatement(src).get('declaration', 'arguments', 0));187 });188 describe('Default class declaration export', () => {189 test('export default class Component {}', src =>190 lastStatement(src).get('declaration'));191 testDecorators(192 'class Component {}',193 src => lastStatement(src).get('declaration'),194 'export default',195 );196 });197 describe('Default class expression export', () => {198 test('export default class {}', src =>199 lastStatement(src).get('declaration'));200 testDecorators(201 'class {}',202 src => lastStatement(src).get('declaration'),203 'export default',204 );205 });206 describe('Default stateless function export', () => {207 describe('named function', () => {208 test('export default function Component() {}', src =>209 lastStatement(src).get('declaration'));210 });211 describe('anonymous function', () => {212 test('export default function() {}', src =>213 lastStatement(src).get('declaration'));214 });215 describe('arrow function', () => {216 test('export default () => {}', src =>217 lastStatement(src).get('declaration'));218 });219 });220 });221 describe('ES6 named exports', () => {222 describe('Named React.createClass export', () => {223 test('export var Component = React.createClass({});', src =>224 lastStatement(src).get(225 'declaration',226 'declarations',227 '0',228 'init',229 'arguments',230 0,231 ));232 });233 describe('Named class declaration export', () => {234 test('export class Component {}', src =>235 lastStatement(src).get('declaration'));236 testDecorators(237 'class Component {}',238 src => lastStatement(src).get('declaration'),239 'export',240 );241 });242 describe('Named stateless function', () => {243 describe('named function', () => {244 test('export function Component() {}', src =>245 lastStatement(src).get('declaration'));246 });247 describe('anonymous function', () => {248 test('export var Component = function() {}', src =>249 lastStatement(src).get('declaration'));250 });251 describe('arrow function', () => {252 test('export var Component = () => {}', src =>253 lastStatement(src).get('declaration'));254 });255 });256 });257 describe('forwardRef', () => {258 const useDefault = true;259 describe('inline implementation', () => {260 test(`261 React.forwardRef((props, ref) => {});262 import React from "react";`, src =>263 beforeLastStatement(src).get('expression'));264 testImports(265 `266 export default React.forwardRef((props, ref) => {});267 import React from 'react';`,...

Full Screen

Full Screen

componentDocblockHandler-test.js

Source:componentDocblockHandler-test.js Github

copy

Full Screen

...9import { parse, noopImporter, makeMockImporter } from '../../../tests/utils';10describe('componentDocblockHandler', () => {11 let documentation;12 let componentDocblockHandler;13 function lastStatement(src) {14 const programPath = parse(src);15 return programPath.get('body', programPath.node.body.length - 1);16 }17 function beforeLastStatement(src) {18 const programPath = parse(src);19 return programPath.get('body', programPath.node.body.length - 2);20 }21 beforeEach(() => {22 documentation = new (require('../../Documentation'))();23 componentDocblockHandler = require('../componentDocblockHandler').default;24 });25 function test(definitionSrc, parseFunc: string => NodePath) {26 it('finds docblocks for component definitions', () => {27 const definition = parseFunc(`28 import something from 'somewhere';29 /**30 * Component description31 */32 ${definitionSrc}33 `);34 componentDocblockHandler(documentation, definition, noopImporter);35 expect(documentation.description).toBe('Component description');36 });37 it('ignores other types of comments', () => {38 let definition = parseFunc(`39 import something from 'somewhere';40 /*41 * This is not a docblock',42 */43 ${definitionSrc}44 `);45 componentDocblockHandler(documentation, definition, noopImporter);46 expect(documentation.description).toBe('');47 definition = parseFunc(`48 // Inline comment'49 ${definitionSrc}50 `);51 componentDocblockHandler(documentation, definition, noopImporter);52 expect(documentation.description).toBe('');53 });54 it('only considers the docblock directly above the definition', () => {55 const definition = parseFunc(`56 import something from 'somewhere';57 /**58 * This is the wrong docblock59 */60 var something_else = "foo";61 ${definitionSrc}62 `);63 componentDocblockHandler(documentation, definition, noopImporter);64 expect(documentation.description).toBe('');65 });66 }67 /**68 * Decorates can only be assigned to class and therefore only make sense for69 * class declarations and export declarations.70 */71 function testDecorators(classSrc, parseFunc, exportSrc = '') {72 describe('decorators', () => {73 it("uses the docblock above the decorator if it's the only one", () => {74 const definition = parseFunc(`75 import something from 'somewhere';76 /**77 * Component description78 */79 ${exportSrc}80 @Decorator181 @Decorator282 ${classSrc}83 `);84 componentDocblockHandler(documentation, definition, noopImporter);85 expect(documentation.description).toBe('Component description');86 });87 it('uses the component docblock if present', () => {88 const definition = parseFunc(`89 import something from 'somewhere';90 ${exportSrc}91 /**92 * Decorator description93 */94 @Decorator195 @Decorator296 /**97 * Component description98 */99 ${classSrc}100 `);101 componentDocblockHandler(documentation, definition, noopImporter);102 expect(documentation.description).toBe('Component description');103 });104 });105 }106 function testImports(exportSrc, parseFunc, importName, useDefault = false) {107 const importDef = useDefault ? `${importName}` : `{ ${importName} }`;108 const mockImporter = makeMockImporter({109 test1: parseFunc(`110 /**111 * Component description112 */113 ${exportSrc}114 `),115 test2: lastStatement(`116 import ${importDef} from 'test1';117 export default ${importName};118 `).get('declaration'),119 });120 describe('imports', () => {121 it('can use a custom importer to resolve docblocks on imported components', () => {122 const program = lastStatement(`123 import ${importDef} from 'test1';124 export default ${importName};125 `).get('declaration');126 componentDocblockHandler(documentation, program, mockImporter);127 expect(documentation.description).toBe('Component description');128 });129 });130 it('traverses multiple imports', () => {131 const program = lastStatement(`132 import ${importDef} from 'test2';133 export default ${importName};134 `).get('declaration');135 componentDocblockHandler(documentation, program, mockImporter);136 expect(documentation.description).toBe('Component description');137 });138 }139 describe('React.createClass', () => {140 test('var Component = React.createClass({})', src =>141 lastStatement(src).get('declarations', 0, 'init', 'arguments', 0));142 testImports(143 'export var Component = React.createClass({})',144 src => lastStatement(src).get('declaration'),145 'Component',146 );147 });148 describe('ClassDeclaration', () => {149 test('class Component {}', src => lastStatement(src));150 testDecorators('class Component {}', src => lastStatement(src));151 testImports(152 'export class Component {}',153 src => lastStatement(src).get('declaration'),154 'Component',155 );156 });157 describe('ClassExpression', () => {158 test('var Component = class {};', src =>159 lastStatement(src).get('declarations', 0, 'init'));160 testImports(161 'export var Component = class {};',162 src => lastStatement(src).get('declaration'),163 'Component',164 );165 });166 describe('Stateless functions', () => {167 test('function Component() {}', src => lastStatement(src));168 testImports(169 'export function Component() {}',170 src => lastStatement(src).get('declaration'),171 'Component',172 );173 test('var Component = function () {};', src =>174 lastStatement(src).get('declarations', 0, 'init'));175 testImports(176 'export var Component = function () {};',177 src => lastStatement(src).get('declaration'),178 'Component',179 );180 test('var Component = () => {}', src =>181 lastStatement(src).get('declarations', 0, 'init'));182 testImports(183 'export var Component = () => {}',184 src => lastStatement(src).get('declaration'),185 'Component',186 );187 });188 describe('ES6 default exports', () => {189 describe('Default React.createClass export', () => {190 test('export default React.createClass({});', src =>191 lastStatement(src).get('declaration', 'arguments', 0));192 });193 describe('Default class declaration export', () => {194 test('export default class Component {}', src =>195 lastStatement(src).get('declaration'));196 testDecorators(197 'class Component {}',198 src => lastStatement(src).get('declaration'),199 'export default',200 );201 });202 describe('Default class expression export', () => {203 test('export default class {}', src =>204 lastStatement(src).get('declaration'));205 testDecorators(206 'class {}',207 src => lastStatement(src).get('declaration'),208 'export default',209 );210 });211 describe('Default stateless function export', () => {212 describe('named function', () => {213 test('export default function Component() {}', src =>214 lastStatement(src).get('declaration'));215 });216 describe('anonymous function', () => {217 test('export default function() {}', src =>218 lastStatement(src).get('declaration'));219 });220 describe('arrow function', () => {221 test('export default () => {}', src =>222 lastStatement(src).get('declaration'));223 });224 });225 });226 describe('ES6 named exports', () => {227 describe('Named React.createClass export', () => {228 test('export var Component = React.createClass({});', src =>229 lastStatement(src).get(230 'declaration',231 'declarations',232 '0',233 'init',234 'arguments',235 0,236 ));237 });238 describe('Named class declaration export', () => {239 test('export class Component {}', src =>240 lastStatement(src).get('declaration'));241 testDecorators(242 'class Component {}',243 src => lastStatement(src).get('declaration'),244 'export',245 );246 });247 describe('Named stateless function', () => {248 describe('named function', () => {249 test('export function Component() {}', src =>250 lastStatement(src).get('declaration'));251 });252 describe('anonymous function', () => {253 test('export var Component = function() {}', src =>254 lastStatement(src).get('declaration'));255 });256 describe('arrow function', () => {257 test('export var Component = () => {}', src =>258 lastStatement(src).get('declaration'));259 });260 });261 });262 describe('forwardRef', () => {263 const useDefault = true;264 describe('inline implementation', () => {265 test(`266 React.forwardRef((props, ref) => {});267 import React from "react";`, src =>268 beforeLastStatement(src).get('expression'));269 testImports(270 `271 export default React.forwardRef((props, ref) => {});272 import React from 'react';`,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { lastStatement } = require('storybook-root');2console.log(lastStatement);3const { lastStatement } = require('storybook-root');4console.log(lastStatement);5const { lastStatement } = require('storybook-root');6console.log(lastStatement);7const { lastStatement } = require('storybook-root');8console.log(lastStatement);9const { lastStatement } = require('storybook-root');10console.log(lastStatement);11const { lastStatement } = require('storybook-root');12console.log(lastStatement);13const { lastStatement } = require('storybook-root');14console.log(lastStatement);15const { lastStatement } = require('storybook-root');16console.log(lastStatement);17const { lastStatement } = require('storybook-root');18console.log(lastStatement);19const { lastStatement } = require('storybook-root');20console.log(lastStatement);21const { lastStatement } = require('storybook-root');22console.log(lastStatement);23const { lastStatement } = require('storybook-root');24console.log(lastStatement);25const { lastStatement } = require('storybook-root');26console.log(lastStatement);27const { lastStatement } = require('storybook-root');28console.log(lastStatement);29const { lastStatement } = require('storybook

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const lastStatement = storybookRoot.lastStatement;3const myLastStatement = lastStatement();4console.log(myLastStatement);5const storybookRoot = require('storybook-root');6const lastStatement = storybookRoot.lastStatement;7const myLastStatement = lastStatement();8console.log(myLastStatement);9const storybookRoot = require('storybook-root');10const lastStatement = storybookRoot.lastStatement;11const myLastStatement = lastStatement();12console.log(myLastStatement);13const storybookRoot = require('storybook-root');14module.exports = storybookRoot;15const storybookRoot = require('./storybook-root');16const lastStatement = storybookRoot.lastStatement;17const myLastStatement = lastStatement();18console.log(myLastStatement);19const storybookRoot = require('./storybook-root');20const lastStatement = storybookRoot.lastStatement;21const myLastStatement = lastStatement();22console.log(myLastStatement);23const storybookRoot = require('./storybook-root');24const lastStatement = storybookRoot.lastStatement;25const myLastStatement = lastStatement();26console.log(myLastStatement);27at Object.<anonymous> (test.js:3:27)28at Module._compile (module.js:653:30)29at Object.Module._extensions..js (module.js:664:10)30at Module.load (module.js:566:32)31at tryModuleLoad (

Full Screen

Using AI Code Generation

copy

Full Screen

1const { lastStatement } = require('storybook-root');2const { expect } = require('chai');3describe('test', () => {4 it('test', () => {5 lastStatement();6 });7});8const { lastStatement } = require('storybook-root');9const { expect } = require('chai');10describe('test2', () => {11 it('test2', () => {12 lastStatement();13 });14});15const { lastStatement } = require('./lib/last-statement');16module.exports = {17};18const { lastStatement } = require('./last-statement');19module.exports = {20};21const { lastStatement } = require('./last-statement');22module.exports = {23};24const { lastStatement } = require('./last-statement');25module.exports = {26};27const { lastStatement } = require('./last-statement');28module.exports = {29};30const { lastStatement } = require('./last-statement');31module.exports = {32};33const { lastStatement } = require('./last-statement');34module.exports = {35};36const { lastStatement } = require('./last-statement');37module.exports = {38};39const { lastStatement } = require('./last-statement');40module.exports = {41};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { lastStatement } from 'storybook-root';2const storybookRoot = lastStatement();3console.log(storybookRoot);4import { lastStatement } from './test';5export const lastStatement = () => {6 const storybookRoot = document.querySelector('#root');7 return storybookRoot;8};9import React from 'react';10import { injectIntl } from 'react-intl';11class TestComponent extends React.Component {12 render() {13 return <div>{this.props.intl.formatMessage({ id: 'test' })}</div>;14 }15}16export default injectIntl(TestComponent);17import React from 'react';18import { shallow } from 'enzyme';19import TestComponent from './TestComponent';20describe('TestComponent', () => {21 it('should inject intl', () => {22 const wrapper = shallow(<TestComponent />);23 const intl = wrapper.find('injectIntl(TestComponent)').prop('intl');24 expect(intl).toBeDefined();25 });26});27jest.mock('react-intl', () => ({28 injectIntl: () => () => {},29}));30jest.mock('react-intl', () => ({31 injectIntl: () => () => ({32 intl: {33 formatMessage: () => {},34 },35 }),36}));

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require("./storybook-root");2let lastStatement = storybookRoot.lastStatement("story1");3console.log(lastStatement);4console.log(storybookRoot.lastStatement("story1"));5console.log(storybookRoot.lastStatement("story2"));6console.log(storybookRoot.lastStatement("story3"));7console.log(storybookRoot.lastStatement("story4"));8console.log(storybookRoot.lastStatement("story5"));9console.log(storybookRoot.lastStatement("story6"));10console.log(storybookRoot.lastStatement("story7"));11console.log(storybookRoot.lastStatement("story8"));12console.log(storybookRoot.lastStatement("story9"));13console.log(storybookRoot.lastStatement("story10"));14console.log(storybookRoot.lastStatement("story11"));15console.log(storybookRoot.lastStatement("story12"));16console.log(storybookRoot.lastStatement("story13"));17console.log(storybookRoot.lastStatement("story14"));18console.log(storybookRoot.lastStatement("story15"));19console.log(storybookRoot.lastStatement("story16"));20console.log(storybookRoot.lastStatement("story17"));21console.log(storybookRoot.lastStatement("story18"));22console.log(storybookRoot.lastStatement("story19"));

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful