Best JavaScript code snippet using storybook-test-runner
film.resolver.ts
Source:film.resolver.ts
1import { Arg, Ctx, Field, FieldResolver, InputType, ObjectType, Query, Resolver, Root } from 'type-graphql';2import { Film } from '../entities/Film';3import { Category } from '../entities/Category';4import { getConnection } from 'typeorm';5import { Actor } from '../entities/Actor';6import { Comment } from '../entities/Comment';7import { ContextType, WithLoaders } from '../types/contextType';8@ObjectType()9class FilmWithCategory extends Film {10 @Field()11 name: string;12}13@InputType()14class PaginationInput {15 @Field({ nullable: true })16 take?: number;17 @Field({ nullable: true })18 after?: number;19}20@ObjectType()21class PaginatedFilms {22 constructor(films: Film[], pagination: PaginationInput) {23 this.films = films;24 const take = pagination.take || 0;25 const after = pagination.after || 0;26 this.cursor = take + after;27 }28 @Field(() => [Film])29 films: Film[];30 @Field()31 cursor: number;32}33@Resolver(() => Film)34class FilmResolver {35 @FieldResolver(() => [Comment], { nullable: true })36 async comments(@Root() film: Film, @Ctx() context: ContextType & WithLoaders) {37 const loader = context.loaders.filmCommentLoader;38 return loader.load(film.film_id);39 }40 @FieldResolver(() => String, { nullable: true })41 async category(@Root() film: Film, @Ctx() context: ContextType & WithLoaders) {42 const loader = context.loaders.categoryLoader;43 return loader.load(film.film_id);44 }45 @FieldResolver(() => [Actor], { nullable: true })46 async actors(@Root() film: Film, @Ctx() context: ContextType & WithLoaders) {47 const loader = context.loaders.actorLoader;48 return loader.load(film.film_id);49 }50 @FieldResolver(() => String, { nullable: true })51 async language(@Root() film: Film, @Ctx() context: ContextType & WithLoaders) {52 const loader = context.loaders.languageLoader;53 return loader.load(film.film_id);54 }55 @Query(() => PaginatedFilms)56 async getAllFilms(@Arg('pagination') pagination: PaginationInput) {57 const skip = pagination.after === null ? 0 : pagination.after;58 const films =59 pagination.take === null60 ? await Film.find({ skip: skip })61 : await Film.find({ skip: skip, take: pagination.take });62 return new PaginatedFilms(films, pagination);63 }64 @Query(() => Film, { nullable: true })65 async getFilmByTitle(@Arg('title') title: string): Promise<Film | null> {66 const film = await Film.findOne({ title: title });67 if (film) {68 return film;69 } else return null;70 }71 @Query(() => [FilmWithCategory], { nullable: true })72 async getFilmsByCategory(@Arg('categoryName') categoryName: string): Promise<FilmWithCategory[] | null> {73 const category = await Category.findOne({ name: categoryName });74 if (!category) return null;75 return (76 (await getConnection().query(`77 select f.*, c.name78 from dvdrental.public.film f,79 dvdrental.public.film_category fc,80 dvdrental.public.category c81 where f.film_id = fc.film_id82 and fc.category_id = ${category.category_id}83 and fc.category_id = c.category_id84 `)) || null85 );86 }87}...
Button.stories.js
Source:Button.stories.js
1import React from 'react';2import { expect } from '@storybook/jest';3import { within, waitFor, userEvent, waitForElementToBeRemoved } from '@storybook/testing-library';4import { Button } from './Button';5export default {6 component: Button,7 argTypes: {8 onSubmit: { action: true },9 },10};11const Template = (args) => <Button {...args} />;12export const Primary = Template.bind({});13Primary.args = {14 primary: true,15 label: 'Button',16};17export const Secondary = Template.bind({});18Secondary.args = {19 ...Primary.args,20 primary: false,21};22Secondary.parameters = {23 tests: {24 disableSnapshots: true,25 },26};27export const Demo = (args) => (28 <button type="button" onClick={() => args.onSubmit('clicked')}>29 Click30 </button>31);32Demo.play = async ({ args, canvasElement }) => {33 await userEvent.click(within(canvasElement).getByRole('button'));34 await expect(args.onSubmit).toHaveBeenCalledWith(expect.stringMatching(/([A-Z])\w+/gi));35};36export const FindBy = (args) => {37 const [isLoading, setIsLoading] = React.useState(true);38 React.useEffect(() => {39 setTimeout(() => setIsLoading(false), 500);40 }, []);41 return isLoading ? <div>Loading...</div> : <button type="button">Loaded!</button>;42};43FindBy.play = async ({ canvasElement }) => {44 const canvas = within(canvasElement);45 await canvas.findByRole('button');46 await expect(true).toBe(true);47};48export const WaitFor = (args) => (49 <button type="button" onClick={() => setTimeout(() => args.onSubmit('clicked'), 100)}>50 Click51 </button>52);53WaitFor.play = async ({ args, canvasElement }) => {54 await userEvent.click(await within(canvasElement).findByText('Click'));55 await waitFor(async () => {56 await expect(args.onSubmit).toHaveBeenCalledWith(expect.stringMatching(/([A-Z])\w+/gi));57 await expect(true).toBe(true);58 });59};60export const WaitForElementToBeRemoved = () => {61 const [isLoading, setIsLoading] = React.useState(true);62 React.useEffect(() => {63 setTimeout(() => setIsLoading(false), 1500);64 }, []);65 return isLoading ? <div>Loading...</div> : <button type="button">Loaded!</button>;66};67WaitForElementToBeRemoved.play = async ({ canvasElement }) => {68 const canvas = within(canvasElement);69 await waitForElementToBeRemoved(await canvas.findByText('Loading...'), { timeout: 2000 });70 const button = await canvas.findByText('Loaded!');71 await expect(button).not.toBeNull();72};73export const WithLoaders = (args, { loaded: { todo } }) => {74 return (75 <button type="button" onClick={args.onSubmit(todo.title)}>76 Todo: {todo.title}77 </button>78 );79};80WithLoaders.loaders = [81 async () => {82 // long fake timeout83 await new Promise((resolve) => setTimeout(resolve, 2000));84 return {85 todo: {86 userId: 1,87 id: 1,88 title: 'delectus aut autem',89 completed: false,90 },91 };92 },93];94WithLoaders.play = async ({ args, canvasElement }) => {95 const canvas = within(canvasElement);96 const todoItem = await canvas.findByText('Todo: delectus aut autem');97 await userEvent.click(todoItem);98 await expect(args.onSubmit).toHaveBeenCalledWith('delectus aut autem');...
etl_job_spec.js
Source:etl_job_spec.js
1const helper = require('./spec_helper');2const ETLJob = require('../src/ETLJob');3describe("etl job run", () => {4 it("should run the etl job with multiple transformers", (done) => {5 let data = "input data to etl";6 let extractor = { fetch: () => Promise.resolve(data), name: "first" };7 let transformer1 = { transform: (data) => Promise.resolve(data.first.split(" ")) };8 let transformer2 = { transform: (data) => Promise.resolve(data.length) }9 let transformer3 = { transform: (data) => Promise.resolve(data+=1) }10 let validator = { validate: (data) => Promise.resolve(data == 5) };11 let loader = { load: (data) => Promise.resolve(data) };12 new ETLJob()13 .withExtractors([extractor])14 .withTransformers([transformer1, transformer2, transformer3])15 .withValidator(validator)16 .withLoaders([loader])17 .run()18 .then(data => {19 expect(data[0]).to.be.true;20 done();21 })22 })23 it("should run the etl job with multiple extractors, transformers and loaders", (done) => {24 let data1 = "first input data to etl";25 let data2 = "second input data to etl";26 let extractor1 = { fetch: () => Promise.resolve(data1), name: "first" };27 let extractor2 = { fetch: () => Promise.resolve(data2), name: "second" };28 let transformer1 = { transform: (data) => Promise.resolve(`${data.first} ${data.second}`) };29 let transformer2 = { transform: (data) => Promise.resolve(data.split(' ').length) }30 let validator = { validate: (data) => Promise.resolve(data) };31 let loader1 = { load: (data) => Promise.resolve(data) };32 let loader2 = { load: (data) => Promise.resolve(data) };33 new ETLJob()34 .withExtractors([extractor1, extractor2])35 .withTransformers([transformer1, transformer2])36 .withValidator(validator)37 .withLoaders([loader1, loader2])38 .run()39 .then(data => {40 expect(data[0]).to.equal(10)41 expect(data[0]).to.equal(data[1]);42 done();43 })44 })...
Using AI Code Generation
1import { WithLoaders } from 'storybook-test-runner';2import { storiesOf } from '@storybook/react';3storiesOf('Test', module)4 .add('test', () => <div>Test</div>)5 .add('test2', () => <div>Test2</div>)6 .add('test3', () => <div>Test3</div>);7describe('Test', () => {8 it('should be true', () => {9 expect(true).toBe(true);10 });11});12WithLoaders('Test', module, () => {13 it('should be true', () => {14 expect(true).toBe(true);15 });16});17WithStory('Test', module, () => {18 it('should be true', () => {19 expect(true).toBe(true);20 });21});22WithStories('Test', module, () => {23 it('should be true', () => {24 expect(true).toBe(true);25 });26});27WithStorybook('Test', module, () => {28 it('should be true', () => {29 expect(true).toBe(true);30 });31});32WithStorybook('Test', module, () => {33 it('should be true', () => {34 expect(true).toBe(true);35 });36});37WithStorybook('Test', module, () => {38 it('should be true', () => {39 expect(true).toBe(true);40 });41});42WithStorybook('Test', module, () => {43 it('should be true', () => {44 expect(true).toBe(true);45 });46});47WithStorybook('Test', module, () => {48 it('should be true', () => {49 expect(true).toBe(true);50 });51});52WithStorybook('Test', module, () => {53 it('should be true', () => {
Using AI Code Generation
1import { WithLoaders } from 'storybook-test-runner';2import { storiesOf } from '@storybook/react';3storiesOf('Test', module)4 .add('test', () => {5 return <div>Test</div>;6 });7WithLoaders(['css', 'sass', 'less', 'stylus', 'png', 'jpg', 'gif', 'svg', 'woff', 'woff2', 'ttf', 'eot', 'otf', 'mp4', 'webm', 'wav', 'mp3', 'm4a', 'aac', 'oga']);8import { testStories } from 'storybook-test-runner';9testStories('stories/**/*.stories.js');10import { testStories } from 'storybook-test-runner';11testStories('stories/**/*.stories.js');12import { testStories } from 'storybook-test-runner';13testStories('stories/**/*.stories.js');14import { testStories } from 'storybook-test-runner';15testStories('stories/**/*.stories.js');16import { testStories } from 'storybook-test-runner';17testStories('stories/**/*.stories.js');18import { testStories } from 'storybook-test-runner';19testStories('stories/**/*.stories.js');20import { testStories } from 'storybook-test-runner';21testStories('stories/**/*.stories.js');22import { testStories } from 'storybook-test-runner';23testStories('stories/**/*.stories.js', {24 webpackConfig: {25 module: {26 {27 },28 },29 },30 webpackFinalConfig: {31 module: {32 {33 },34 },35 },
Using AI Code Generation
1import { WithLoaders } from 'storybook-test-runner';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { linkTo } from '@storybook/addon-links';5import { WithLoaders } from 'storybook-test-runner';6import { storiesOf } from '@storybook/react';7import { action } from '@storybook/addon-actions';8import { linkTo } from '@storybook/addon-links';9import { WithLoaders } from 'storybook-test-runner';10import { storiesOf } from '@storybook/react';11import { action } from '@storybook/addon-actions';12import { linkTo } from '@storybook/addon-links';13import { WithLoaders } from 'storybook-test-runner';14import { storiesOf } from '@storybook/react';15import { action } from '@storybook/addon-actions';16import { linkTo } from '@storybook/addon-links';17import { WithLoaders } from 'storybook-test-runner';18import { storiesOf } from '@storybook/react';19import { action } from '@storybook/addon-actions';20import { linkTo } from '@storybook/addon-links';21import { WithLoaders } from 'storybook-test-runner';22import { storiesOf } from '@storybook/react';23import { action } from '@storybook/addon-actions';24import { linkTo } from '@storybook/addon-links';25import { WithLoaders } from 'storybook-test-runner';26import { storiesOf } from '@storybook/react';27import { action } from '@storybook/addon-actions';28import { linkTo } from '@storybook/addon-links';
Using AI Code Generation
1const { WithLoaders } = require('storybook-test-runner');2const { render } = require('@testing-library/react');3const { Story } = require('./Story');4describe('Story', () => {5 it('should render', () => {6 const { getByText } = render(7 WithLoaders(Story, {8 {9 },10 {11 },12 })13 );14 expect(getByText('Story')).toBeTruthy();15 });16});17import React from 'react';18import './Story.css';19export const Story = () => <div className="story">Story</div>;20.story {21 background: url('./story.svg');22}
Using AI Code Generation
1import React from 'react';2import { WithLoaders } from 'storybook-test-runner';3import { storiesOf } from '@storybook/react';4import { Button } from '@storybook/react/demo';5storiesOf('Button', module)6 .add('with text', () => (7 <Button onClick={action('clicked')}>Hello Button</Button>8 .add('with some emoji', () => (9 <Button onClick={action('clicked')}>10 ));11WithLoaders({12 storybook: {13 configPath: path.resolve(__dirname, '../.storybook'),14 },15 testPath: path.resolve(__dirname, './test.js'),16 storybookOutputPath: path.resolve(__dirname, '../.storybook-static'),17 storybookBuildPath: path.resolve(__dirname, '../.storybook-static'),18 storybookPublicPath: path.resolve(__dirname, '../.storybook-static'),19 storybookStaticDir: path.resolve(__dirname, '../.storybook-static'),20 storybookWebpackConfigPath: path.resolve(__dirname, '../.storybook/webpack.config.js'),21 storybookConfigDir: path.resolve(__dirname, '../.storybook'),22 storybookConfigOutputDir: path.resolve(__dirname, '../.storybook-static'),23 storybookBuildConfigDir: path.resolve(__dirname, '../.storybook'),24 storybookBuildConfigOutputDir: path.resolve(__dirname, '../.storybook-static'),
Using AI Code Generation
1import { WithLoaders } from 'storybook-test-runner';2import { withKnobs } from '@storybook/addon-knobs';3import { configure } from '@storybook/react';4const req = require.context('../stories', true, /\.stories\.js$/);5const loadStories = () => {6 WithLoaders(req, configure);7};8export default loadStories;9import { WithLoaders } from 'storybook-test-runner';10import { withKnobs } from '@storybook/addon-knobs';11import { configure } from '@storybook/react';12const req = require.context('../stories', true, /\.stories\.js$/);13const loadStories = () => {14 WithLoaders(req, configure);15};16export default loadStories;17import { WithLoaders } from 'storybook-test-runner';18import { withKnobs } from '@storybook/addon-knobs';19import { configure } from '@storybook/react';20const req = require.context('../stories', true, /\.stories\.js$/);21const loadStories = () => {22 WithLoaders(req, configure);23};24export default loadStories;25import { WithLoaders } from 'storybook-test-runner';26import { withKnobs } from '@storybook/addon-knobs';27import { configure } from '@storybook/react';28const req = require.context('../stories', true, /\.stories\.js$/);29const loadStories = () => {30 WithLoaders(req, configure);31};32export default loadStories;33import { WithLoaders } from 'storybook-test-runner
Using AI Code Generation
1import { WithLoaders } from 'storybook-test-runner';2import { stories } from './stories';3const customLoader = (story, context) => {4 return story;5};6WithLoaders(stories, customLoader).test();7export const stories = {8 storyName: () => {9 return 'story content';10 }11};12import { WithLoaders } from 'storybook-test-runner';13import { stories } from './stories';14const customLoader = (story, context) => {15 return story;16};17WithLoaders(stories, customLoader).test();18export const stories = {19 storyName: () => {20 return 'story content';21 }22};23import { WithLoaders } from 'storybook-test-runner';24import { stories } from './stories';25const customLoader = (story, context) => {26 return story;27};28WithLoaders(stories, customLoader).test();29export const stories = {30 storyName: () => {31 return 'story content';32 }33};34import { WithLoaders } from 'storybook-test-runner';35import { stories } from './stories';36const customLoader = (story, context) => {37 return story;38};39WithLoaders(stories, customLoader).test();40export const stories = {41 storyName: () => {42 return 'story content';43 }44};45import { WithLoaders } from 'storybook-test-runner';46import { stories } from
Using AI Code Generation
1const { WithLoaders } = require('story-test-runner');2const loaders = require('./loaders');3const { stories } = WithLoaders(loaders);4const { WithStories } = require('story-test-runner');5const { stories } = WithStories(stories);6const { WithStories } = require('story-test-runner');7const { stories } = WithStories();8const { WithStories, WithLoaders } = require('story-test-runner');9const loaders = require('./loaders');10const { stories } = WithStories(WithLoaders(loaders));11const { WithStories, WithLoaders } = require('story-test-runner');12const loaders = require('./loaders');13const { stories } = WithStories(WithLoaders(WithStories(loaders)));14const { WithStories, WithLoaders } = require('story-test-runner');15const loaders = require('./loaders');
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!