Best JavaScript code snippet using storybook-root
createActionExecutor.spec.js
Source:createActionExecutor.spec.js
1const expect = require('chai').expect2const sinon = require('sinon')3const Bluebird = require('bluebird')4const ActionStatus = require('../../src/constants').ActionStatus5const ImmediateResult = require('../../src/ImmediateResult')6const createActionExecutor = require('../../src/internal/createActionExecutor')7const ServiceActionNotFoundError = require('../../src/ServiceError/ServiceActionNotFoundError')8const waitTick = () => new Promise(resolve => setTimeout(resolve))9const waitTickBluebird = () => new Bluebird(resolve => setTimeout(resolve))10describe('core', () => {11 describe('createActionExecutor', () => {12 it('should throw error without required options', () => {13 expect(() => createActionExecutor({})).to.throw()14 expect(() => createActionExecutor({ createContext: () => ({}) })).to.throw()15 })16 it('should create a function', () => {17 const fn = createActionExecutor({18 createContext: () => ({}),19 execute: () => true20 })21 expect(typeof fn).to.equal('function')22 })23 it('should return a valid promise', async () => {24 const fn = createActionExecutor({25 createContext: () => ({}),26 execute: () => 'blabla'27 })28 const result = fn()29 expect(typeof result.then).to.equal('function')30 const resolvedResult = await result31 expect(resolvedResult).to.equal('blabla')32 })33 it('should pass execution data for context function', async () => {34 const createContext = sinon.fake.returns({})35 const fn = createActionExecutor({36 createContext: createContext,37 execute: () => true38 })39 await fn('some-name', { par: 'ams', papa: 'dams' }, { some: 'meta', data: null })40 expect(createContext.called).to.equal(true)41 expect(createContext.calledWith(42 'some-name',43 { par: 'ams', papa: 'dams' },44 { some: 'meta', data: null }45 )).to.equal(true)46 })47 it('should pass context to executor', async () => {48 const ctx = { a: 10, b: 20, c: 30 }49 const executor = sinon.fake.returns(true)50 const fn = createActionExecutor({51 createContext: () => ctx,52 execute: executor53 })54 await fn()55 expect(executor.called).to.equal(true)56 expect(executor.calledWith(ctx)).to.equal(true)57 })58 it('should pass context to each function down', async () => {59 const ctx = { a: 10, b: 20, c: 30 }60 const processor = sinon.fake.returns(null)61 const preExecutor = sinon.fake.returns(null)62 const executor = sinon.fake.returns(null)63 const finalizer = sinon.fake.returns(null)64 const resultProcessor = sinon.fake.returns(null)65 const fn = createActionExecutor({66 createContext: () => ctx,67 process: processor,68 preExecute: preExecutor,69 execute: executor,70 processResult: resultProcessor,71 finalizeContext: finalizer72 })73 await fn()74 expect(processor.called).to.equal(true)75 expect(processor.calledWith(ctx)).to.equal(true)76 expect(preExecutor.called).to.equal(true)77 expect(preExecutor.calledWith(ctx)).to.equal(true)78 expect(executor.called).to.equal(true)79 expect(executor.calledWith(ctx)).to.equal(true)80 expect(finalizer.called).to.equal(true)81 expect(finalizer.calledWith(ctx, null)).to.equal(true)82 expect(resultProcessor.called).to.equal(true)83 expect(resultProcessor.calledWith(null, ctx)).to.equal(true)84 })85 it('should properly execute function', async () => {86 const fn = createActionExecutor({87 createContext: (name, params) => ({ name, params }),88 execute: (ctx) => ctx.params.a + ctx.params.b89 })90 const result = await fn('bla', { a: 10, b: 20 })91 expect(result).to.equal(30)92 })93 it('should allow mutating context', async () => {94 const createContext = (name, params) => ({95 name: name,96 params: {97 a: params.a * 5,98 b: params.b * 599 }100 })101 const mutateContext = ctx => {102 ctx.params.a *= 2103 ctx.params.b *= 3104 }105 const fn = createActionExecutor({106 createContext: createContext,107 process: mutateContext,108 preExecute: mutateContext,109 execute: (ctx) => ctx.params.a + ctx.params.b110 })111 const result = await fn('bla', { a: 10, b: 20 })112 expect(result).to.equal(1100)113 })114 it('should allow processing result', async () => {115 const createContext = (name, params) => ({116 name: name,117 params: params118 })119 const fn = createActionExecutor({120 createContext: createContext,121 execute: (ctx) => ctx.params.a + ctx.params.b,122 processResult: (value, ctx) => `${value} ${ctx.name}`123 })124 const result = await fn('apples', { a: 10, b: 20 })125 expect(result).to.equal('30 apples')126 })127 it('should handle asynchronous paths', async () => {128 const createContext = (name, params) => ({129 name: name,130 params: params131 })132 const mutateContextAsynchronously = ctx => {133 return new Promise((resolve) => setTimeout(() => {134 ctx.params.a *= 2135 ctx.params.b *= 3136 resolve()137 }))138 }139 const fn = createActionExecutor({140 createContext: createContext,141 process: mutateContextAsynchronously,142 preExecute: mutateContextAsynchronously,143 execute: (ctx) => ctx.params.a + ctx.params.b144 })145 const result = await fn('bla', { a: 10, b: 20 })146 expect(result).to.equal(220)147 })148 it('should allow only selected methods', async () => {149 const isActionSupported = name => name === 'allowedName'150 const createContext = (name, params) => ({ name: name, params: params })151 const fn = createActionExecutor({152 isActionSupported: isActionSupported,153 createContext: createContext,154 execute: (ctx) => ctx.params.a + ctx.params.b155 })156 const success = sinon.fake()157 const failure = sinon.fake()158 await fn('bla', { a: 10, b: 20 })159 .then(success, failure)160 .catch(() => {})161 expect(success.called).to.equal(false)162 expect(failure.called).to.equal(true)163 expect(failure.lastArg instanceof ServiceActionNotFoundError).to.equal(true)164 const success2 = sinon.fake()165 const failure2 = sinon.fake()166 await fn('allowedName', { a: 10, b: 20 })167 .then(success2, failure2)168 .catch(() => {})169 expect(success2.called).to.equal(true)170 expect(failure2.called).to.equal(false)171 expect(success2.lastArg).to.equal(30)172 })173 it('should emit events on each step of action execution (success)', async () => {174 const context = { a: 10, b: 20 }175 const createContext = () => context176 const events = []177 const onActionStateChange = (state, context, value) => events.push({178 state: state,179 context: context,180 value: value181 })182 const fn = createActionExecutor({183 createContext: createContext,184 onActionStateChange: onActionStateChange,185 execute: (ctx) => ctx.a + ctx.b186 })187 await fn('bla')188 expect(events).to.deep.equal([189 { state: ActionStatus.CREATED, context: context, value: undefined },190 { state: ActionStatus.READY, context: context, value: undefined },191 { state: ActionStatus.EXECUTION, context: context, value: undefined },192 { state: ActionStatus.SUCCESS, context: context, value: 30 }193 ])194 })195 it('should emit events on each step of action execution (unknown action)', async () => {196 const context = { a: 10, b: 20 }197 const createContext = () => context198 const isActionSupported = name => name === 'allowedName'199 const events = []200 const onActionStateChange = (state, context, value) => events.push({201 state: state,202 context: context,203 value: value204 })205 const fn = createActionExecutor({206 isActionSupported: isActionSupported,207 createContext: createContext,208 onActionStateChange: onActionStateChange,209 execute: (ctx) => ctx.a + ctx.b210 })211 await fn('bla').catch(() => {})212 expect(events).to.deep.equal([213 { state: ActionStatus.CREATED, context: context, value: undefined },214 { state: ActionStatus.UNKNOWN, context: context, value: undefined }215 ])216 })217 it('should emit events on each step of action execution (failure)', async () => {218 const context = { a: 10, b: 20 }219 const createContext = () => context220 const events = []221 const onActionStateChange = (state, context, value) => events.push({222 state: state,223 context: context,224 value: value225 })226 const fn = createActionExecutor({227 createContext: createContext,228 onActionStateChange: onActionStateChange,229 execute: (ctx) => ctx.unknownProperty.a + ctx.b230 })231 await fn('bla').catch(() => {})232 expect(events.length).to.equal(4)233 expect(events[3].value instanceof TypeError).to.equal(true)234 expect(events).to.deep.equal([235 { state: ActionStatus.CREATED, context: context, value: undefined },236 { state: ActionStatus.READY, context: context, value: undefined },237 { state: ActionStatus.EXECUTION, context: context, value: undefined },238 { state: ActionStatus.ERROR, context: context, value: events[3].value }239 ])240 })241 it('should emit events on each step of action execution (faster failure)', async () => {242 const context = { a: 10, b: 20 }243 const createContext = () => context244 const events = []245 const onActionStateChange = (state, context, value) => events.push({246 state: state,247 context: context,248 value: value249 })250 const fn1 = createActionExecutor({251 createContext: createContext,252 onActionStateChange: onActionStateChange,253 process: (ctx) => ctx.unknownProperty.a + ctx.b,254 execute: (ctx) => ctx.a + ctx.b255 })256 await fn1('bla').catch(() => {})257 expect(events.length).to.equal(2)258 expect(events[1].value instanceof TypeError).to.equal(true)259 expect(events).to.deep.equal([260 { state: ActionStatus.CREATED, context: context, value: undefined },261 { state: ActionStatus.ERROR, context: context, value: events[1].value }262 ])263 const fn2 = createActionExecutor({264 createContext: createContext,265 onActionStateChange: onActionStateChange,266 preExecute: (ctx) => ctx.unknownProperty.a + ctx.b,267 execute: (ctx) => ctx.a + ctx.b268 })269 events.splice(0, events.length)270 await fn2('bla').catch(() => {})271 expect(events.length).to.equal(3)272 expect(events[2].value instanceof TypeError).to.equal(true)273 expect(events).to.deep.equal([274 { state: ActionStatus.CREATED, context: context, value: undefined },275 { state: ActionStatus.READY, context: context, value: undefined },276 { state: ActionStatus.ERROR, context: context, value: events[2].value }277 ])278 })279 it('should return result before action execution', async () => {280 const context = { a: 10, b: 20 }281 const createContext = () => context282 const events = []283 const onActionStateChange = (state, context, value) => events.push({284 state: state,285 context: context,286 value: value287 })288 const fn = createActionExecutor({289 createContext: createContext,290 onActionStateChange: onActionStateChange,291 process: () => { throw new ImmediateResult('something') },292 execute: (ctx) => ctx.a + ctx.b293 })294 const result1 = await fn('bla')295 expect(result1).to.equal('something')296 expect(events.length).to.equal(2)297 expect(events).to.deep.equal([298 { state: ActionStatus.CREATED, context: context, value: undefined },299 { state: ActionStatus.SUCCESS, context: context, value: 'something' }300 ])301 const asyncFn = createActionExecutor({302 createContext: createContext,303 onActionStateChange: onActionStateChange,304 preExecute: waitTick,305 process: () => { throw new ImmediateResult('something') },306 execute: (ctx) => ctx.a + ctx.b307 })308 events.splice(0, events.length)309 const result2 = await asyncFn('bla')310 expect(result2).to.equal('something')311 expect(events.length).to.equal(2)312 expect(events).to.deep.equal([313 { state: ActionStatus.CREATED, context: context, value: undefined },314 { state: ActionStatus.SUCCESS, context: context, value: 'something' }315 ])316 })317 it('should process immediate result', async () => {318 const context = { a: 10, b: 20 }319 const createContext = () => context320 const events = []321 const onActionStateChange = (state, context, value) => events.push({322 state: state,323 context: context,324 value: value325 })326 const fn = createActionExecutor({327 createContext: createContext,328 onActionStateChange: onActionStateChange,329 process: () => { throw new ImmediateResult('something') },330 processResult: (result) => `${result} there`,331 execute: (ctx) => ctx.a + ctx.b332 })333 const result = await fn('bla')334 expect(result).to.equal('something there')335 expect(events.length).to.equal(2)336 expect(events).to.deep.equal([337 { state: ActionStatus.CREATED, context: context, value: undefined },338 { state: ActionStatus.SUCCESS, context: context, value: 'something there' }339 ])340 })341 it('should choose proper Promise implementation', async () => {342 const context = { a: 10, b: 20 }343 const createContext = () => context344 const fn = createActionExecutor({345 Promise: Bluebird,346 createContext: createContext,347 processResult: (result) => `${result} there`,348 execute: (ctx) => ctx.a + ctx.b349 })350 const promise1 = fn('bla')351 await promise1352 expect(promise1 instanceof Bluebird).to.equal(true)353 const asyncFn = createActionExecutor({354 Promise: Bluebird,355 createContext: createContext,356 preExecute: waitTick,357 execute: (ctx) => ctx.a + ctx.b358 })359 const promise2 = asyncFn('bla')360 await promise2361 expect(promise2 instanceof Bluebird).to.equal(true)362 })363 it('could reuse Promise implementation sent inside', async () => {364 const context = { a: 10, b: 20 }365 const createContext = () => context366 const fn1 = createActionExecutor({367 ensurePromiseImplementation: false,368 Promise: Bluebird,369 preExecute: waitTick, // it will use native Promise370 createContext: createContext,371 execute: (ctx) => ctx.a + ctx.b372 })373 const promise1 = fn1('bla')374 await promise1375 expect(promise1 instanceof Promise).to.equal(true)376 const fn2 = createActionExecutor({377 ensurePromiseImplementation: false,378 Promise: Promise,379 preExecute: waitTickBluebird, // it will use Bluebird promises380 createContext: createContext,381 execute: (ctx) => ctx.a + ctx.b382 })383 const promise2 = fn2('bla')384 await promise2385 expect(promise2 instanceof Bluebird).to.equal(true)386 })387 it('should attach context to promise (success)', async () => {388 const context = { a: 10, b: 20 }389 const createContext = () => context390 const fn = createActionExecutor({391 createContext: createContext,392 execute: (ctx) => ctx.a + ctx.b393 })394 const promise = fn('bla')395 expect(promise.context).to.equal(context)396 await promise397 expect(promise.context).to.equal(context)398 })399 it('should not attach context to promise (success)', async () => {400 const context = { a: 10, b: 20 }401 const createContext = () => context402 const fn = createActionExecutor({403 includeContext: false,404 createContext: createContext,405 execute: (ctx) => ctx.a + ctx.b406 })407 const promise = fn('bla')408 expect(promise.context).to.equal(undefined)409 await promise410 expect(promise.context).to.equal(undefined)411 })412 it('should attach context to promise (unknown action)', async () => {413 const context = { a: 10, b: 20 }414 const createContext = () => context415 const isActionSupported = () => false416 const fn = createActionExecutor({417 isActionSupported: isActionSupported,418 createContext: createContext,419 execute: (ctx) => ctx.a + ctx.b420 })421 const promise = fn('bla')422 promise.catch(() => {})423 expect(promise.context).to.equal(context)424 await promise.catch(() => {})425 expect(promise.context).to.equal(context)426 })427 it('should not attach context to promise (unknown action)', async () => {428 const context = { a: 10, b: 20 }429 const createContext = () => context430 const isActionSupported = () => false431 const fn = createActionExecutor({432 includeContext: false,433 isActionSupported: isActionSupported,434 createContext: createContext,435 execute: (ctx) => ctx.a + ctx.b436 })437 const promise = fn('bla')438 promise.catch(() => {})439 expect(promise.context).to.equal(undefined)440 await promise.catch(() => {})441 expect(promise.context).to.equal(undefined)442 })443 it('should attach context to promise (failure)', async () => {444 const context = { a: 10, b: 20 }445 const createContext = () => context446 const fn = createActionExecutor({447 createContext: createContext,448 preExecute: () => { throw new Error() },449 execute: (ctx) => ctx.a + ctx.b450 })451 const promise = fn('bla')452 promise.catch(() => {})453 expect(promise.context).to.equal(context)454 await promise.catch(() => {})455 expect(promise.context).to.equal(context)456 })457 it('should not attach context to promise (failure)', async () => {458 const context = { a: 10, b: 20 }459 const createContext = () => context460 const fn = createActionExecutor({461 includeContext: false,462 createContext: createContext,463 preExecute: () => { throw new Error() },464 execute: (ctx) => ctx.a + ctx.b465 })466 const promise = fn('bla')467 promise.catch(() => {})468 expect(promise.context).to.equal(undefined)469 await promise.catch(() => {})470 expect(promise.context).to.equal(undefined)471 })472 it('should ignore uncaught error (within emitting events)', async () => {473 const context = { a: 10, b: 20 }474 const createContext = () => context475 const fn = createActionExecutor({476 includeContext: false,477 createContext: createContext,478 onActionStateChange: () => { throw new Error('Meh.') },479 execute: (ctx) => ctx.a + ctx.b480 })481 const result = await fn('bla')482 expect(result).to.equal(30)483 })484 it('should handle uncaught error (within emitting events)', async () => {485 const context = { a: 10, b: 20 }486 const createContext = () => context487 const onUncaughtError = sinon.fake()488 const fn = createActionExecutor({489 includeContext: false,490 createContext: createContext,491 onActionStateChange: () => { throw new Error('Meh.') },492 onUncaughtError: onUncaughtError,493 execute: (ctx) => ctx.a + ctx.b494 })495 const result = await fn('bla')496 expect(result).to.equal(30)497 expect(onUncaughtError.called).to.equal(true)498 expect(onUncaughtError.lastArg instanceof Error).to.equal(true)499 expect(onUncaughtError.lastArg.message).to.equal('Meh.')500 })501 })...
lisp.test.js
Source:lisp.test.js
...11 console.log.mockRestore();12});13describe('evaluateExpression', () => {14 it('evaluates atoms', () => {15 expect(evaluateExpression(1, createContext())).toBe(1);16 expect(evaluateExpression(-101, createContext())).toBe(-101);17 expect(evaluateExpression(123.456, createContext())).toBe(123.456);18 expect(evaluateExpression(true, createContext())).toBe(true);19 expect(evaluateExpression(null, createContext())).toBe(null);20 });21 it('adds two numbers together', () => {22 expect(evaluateExpression(['+', 1, 2], createContext())).toBe(3);23 expect(evaluateExpression(['+', 0, 0], createContext())).toBe(0);24 expect(evaluateExpression(['+', 2.5, 8.6], createContext())).toBe(11.1);25 expect(evaluateExpression(['+', 2, -6], createContext())).toBe(-4);26 });27 it('adds lists of numbers together', () => {28 expect(evaluateExpression(['+', 1, 2, 3, 4], createContext())).toBe(10);29 expect(evaluateExpression(['+', 5], createContext())).toBe(5);30 expect(31 evaluateExpression(32 ['+', 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],33 createContext(),34 ),35 ).toBe(0);36 });37 it('subtracts numbers', () => {38 expect(evaluateExpression(['-', 10, 2], createContext())).toBe(8);39 expect(evaluateExpression(['-', 10, -2], createContext())).toBe(12);40 expect(evaluateExpression(['-', 10, 2, 3, 2], createContext())).toBe(3);41 });42 it('multiplies numbers', () => {43 expect(evaluateExpression(['*', 10, 2], createContext())).toBe(20);44 expect(evaluateExpression(['*', 10, -2], createContext())).toBe(-20);45 expect(evaluateExpression(['*', 10, 2, 2], createContext())).toBe(40);46 });47 it('divides numbers', () => {48 expect(evaluateExpression(['/', 10, 2], createContext())).toBe(5);49 expect(evaluateExpression(['/', 10, -2], createContext())).toBe(-5);50 expect(evaluateExpression(['/', 10, 2, 2], createContext())).toBe(2.5);51 });52 it('evaluates nested expressions', () => {53 expect(54 evaluateExpression(['+', ['+', 1, 2], ['+', 3, 4]], createContext()),55 ).toBe(10);56 expect(57 evaluateExpression(58 ['*', ['+', 1, 2, 3, 4], ['-', 10, 4]],59 createContext(),60 ),61 ).toBe(60);62 expect(63 evaluateExpression(64 ['*', ['+', 10, ['/', 100, 10]], ['-', ['+', 10, 5], 5]],65 createContext(),66 ),67 ).toBe(200);68 });69 describe('print', () => {70 it('calls console.log', () => {71 evaluateExpression(['print', 123], createContext());72 expect(console.log).toHaveBeenCalledTimes(1);73 expect(console.log).toHaveBeenLastCalledWith(123);74 });75 it('can be called with several arguments', () => {76 evaluateExpression(['print', 1, 2, 3], createContext());77 expect(console.log).toHaveBeenCalledTimes(1);78 expect(console.log).toHaveBeenLastCalledWith(1, 2, 3);79 });80 it('evaluates nested arguments', () => {81 evaluateExpression(['print', ['+', 5, ['*', 12, 5]]], createContext());82 expect(console.log).toHaveBeenCalledTimes(1);83 expect(console.log).toHaveBeenLastCalledWith(65);84 });85 it('returns undefined', () => {86 expect(evaluateExpression(['print', 0], createContext())).toBe(undefined);87 });88 });89 describe('if', () => {90 it('returns the correct branch based on a condition', () => {91 const expr1 = ['if', true, ['+', 0, 1], ['*', 10, 2]];92 expect(evaluateExpression(expr1, createContext())).toBe(1);93 const expr2 = ['if', false, ['+', 0, 1], ['*', 10, 2]];94 expect(evaluateExpression(expr2, createContext())).toBe(20);95 });96 it('evaluates the condition as an expression', () => {97 expect(98 evaluateExpression(['if', ['+', 1, 1], 1, 2], createContext()),99 ).toBe(1);100 expect(101 evaluateExpression(['if', ['+', 1, -1], 1, 2], createContext()),102 ).toBe(2);103 });104 it('only evaluates one branch', () => {105 evaluateExpression(106 ['if', true, ['print', 1], ['print', 2]],107 createContext(),108 );109 expect(console.log).toHaveBeenCalledTimes(1);110 expect(console.log).toHaveBeenLastCalledWith(1);111 evaluateExpression(112 ['if', false, ['print', 1], ['print', 2]],113 createContext(),114 );115 expect(console.log).toHaveBeenCalledTimes(2);116 expect(console.log).toHaveBeenLastCalledWith(2);117 });118 it('returns undefined if condition is not met with no else-branch', () => {119 expect(evaluateExpression(['if', false, 1], createContext())).toBe(120 undefined,121 );122 });123 });124});125describe('evaluateProgram', () => {126 it('evaluates a sequence of expressions', () => {127 evaluateProgram(128 [129 ['print', ['+', 2, 2]],130 ['if', true, ['print', 1], ['print', 2]],131 ['print', 123, 456, 789],132 ],133 createContext(),134 );135 expect(console.log.mock.calls).toEqual([[4], [1], [123, 456, 789]]);136 });137});138describe('createContext', () => {139 it('retrieves defined variables', () => {140 const context = createContext();141 context.define('x', 13);142 context.define('myAge', 25);143 expect(context.get('x')).toBe(13);144 expect(context.get('myAge')).toBe(25);145 });146 it('overwrites pre-defined variables', () => {147 const context = createContext();148 context.define('x', 13);149 expect(context.get('x')).toBe(13);150 context.define('x', 26);151 expect(context.get('x')).toBe(26);152 });153 it('throws an error when a variable is not defined', () => {154 const context = createContext();155 expect(() => context.get('x')).toThrowError('x is not defined');156 });...
contexts.js
Source:contexts.js
1import { createContext } from 'react'2//for app.js3export const BrightThemeContext = createContext(false)4export const FirstnameContext = createContext({ firstname: null, setFirstname: _ => {} })5export const UserIdContext = createContext(null)6export const IsAuthContext = createContext(false)7export const UnseenMsgsContext = createContext({ set: _ => {}, messages: 0 })8export const IncomingReqsContext = createContext({ set: _ => {}, requests: 0 })9export const LogoutHandlerContext = createContext(_ => {})10export const LoginHandlerContext = createContext(_ => {})11export const AcceptEmailContext = createContext(_ => {})12export const ToggleThemeContext = createContext(_ => {}) 13export const SignalContext = createContext(null)14export const SetTodoToDeleteContext = createContext(_ => {})15export const YourTodoContext = createContext(null)16export const CloseModalContext = createContext(_ => {})17export const SetNewTodoContext = createContext(_ => {})18export const TodoStatsContext = createContext({})19export const SetTodoToUpdateContext = createContext({})20export const TodoToUpdateContext = createContext({value : {}, unset: _ => {}})21export const OpenModalContext = createContext(_ => {})22export const PassTodoDataContext = createContext(_ => {})23export const TodoDataContext = createContext({})24export const UserDataContext = createContext({})25export const EditUserContext = createContext('')26export const SetEditUserContext = createContext({ value: '', set: _ => {} })27export const SetUpdatedUserContext = createContext(_ => {})28export const ViewUserStatsContext = createContext({ value: '', set: _ => {} })29export const SetItemToDeleteContext = createContext(_ => {})30export const DecreaseUserStatsContext = createContext(_ => {})31export const IncreaseUserStatsContext = createContext(_ => {})32export const UnfollowUserContext = createContext(_ => {})33export const SetBlockingUserContext = createContext(_ => {})34export const FollowControlsContext = createContext(null)35export const ConversationsContext = createContext({ convs: [], total: null })36export const LoadingContext = createContext(false)37export const PageContext = createContext({ page: 1, setPage: _ => {} })38export const HasNextPageContext = createContext({ has: false, set: _ => {} })39export const SetConvToDeleteContext = createContext(_ => {})40export const SetConvToEditContext = createContext(_ => {})41export const SetConvToAddContext = createContext(_ => {})42export const CurrentlyOpenedConvContext = createContext({ value: null, set: _ => {}})43export const QuitHandlerContext = createContext(_ => {})44export const ReceiverContext = createContext('')45export const SetMessageContext = createContext({})46export const SetMessageToEditLocallyContext = createContext({ value: null, set: _ => {} })47//export...
ContextFile.js
Source:ContextFile.js
1import { createContext } from "react";2export const UserLatContext = createContext();3export const UserLngContext = createContext();4export const FormRequestContext = createContext();5const UserContext = createContext();6export default UserContext;7export const AllRequestContext = createContext();8export const FirstNameContext = createContext();9export const UserIdContext = createContext();10export const RequestOwnerContext = createContext();11export const AllVolunteerContext = createContext();12export const RequestIdContext = createContext();13export const ReqOwnerFirstNameContext = createContext();14export const ChatContext = createContext();15export const AllMessagesContext = createContext();16export const AllRoomContext = createContext();17export const SelectedRoomContext = createContext();18export const SelectedChatContext = createContext();19export const SelectedReqDescContext = createContext();20export const SelectedRequestContext = createContext();21export const ChatRoomIdContext = createContext();22export const AllUserIdContext = createContext();23export const RequestOwnerIdContext = createContext();24export const CurrentRoomContext = createContext();25export const UserClickedRequest = createContext();26export const SameUserClickCount = createContext();27export const PannedMapContext = createContext()28export const RequestFormContext = createContext();29export const CurrentVolunteerContext = createContext();30export const DeactivateContext = createContext();31export const RepublishRequestContext = createContext();32export const RoomToRepublishContext = createContext()33export const RepublishingContext = createContext()34// for chat 35export const CurrentUserContext = createContext();36export const RoomDataContext = createContext();37export const HelperTextContext = createContext();...
contextObjects.js
Source:contextObjects.js
1import React from 'react'2// INITIALIZATION OF CONTEXT OBJECTS - FOR HEADERS3export const CurrentUser = React.createContext({});4export const LoginBarToggle = React.createContext('');5export const StoreIdContext = React.createContext('');6export const StoreAddressContext = React.createContext('');7export const StorePhoneContext = React.createContext('');8export const StoreHoursContext = React.createContext('');9export const StoreExchangePolicyContext = React.createContext('');10export const InstagramContext = React.createContext('');11// INITIALIZATION OF CONTEXT OBJECTS - FOR PRICES12export const ChildrensPriceContext = React.createContext('');13export const HardcoverPriceContext = React.createContext('');14export const SoftcoverPriceContext = React.createContext('');15export const AlbumsPriceContext = React.createContext('');16export const CdsPriceContext = React.createContext('');17export const DvdsPriceContext = React.createContext('');18export const SetsPriceContext = React.createContext('');...
index.js
Source:index.js
1import { createContext } from 'react';2export const AuthUserContext = createContext();3export const ContentContext = createContext();4export const CategoryContext = createContext();5export const FirebaseContext = createContext();6export const OptFormEmailContext = createContext();7export const ProfileContext = createContext();8export const ProfileListContext = createContext();9export const SetAuthUserContext = createContext();10export const SetCategoryContext = createContext();11export const SetContentContext = createContext();12export const SetOptFormEmailContext = createContext();13export const SetProfileContext = createContext();14export const SetProfileListContext = createContext();15export const SetTermContext = createContext();...
context.js
Source:context.js
1import React from 'react';2export const AuthContext = React.createContext();3// export const DataContext = React.createContext();4export const CommandContext = React.createContext();5export const ShowDataOpen = React.createContext();6export const DataStatusContext = React.createContext();7export const ImpContext = React.createContext();8export const BoundAddress = React.createContext();9export const Loading = React.createContext();10export const PairedDs = React.createContext();11export const FoundDs = React.createContext();12export const BleOpend = React.createContext();13export const Name = React.createContext();...
state.js
Source:state.js
1import { createContext } from "react";2export const DeleteFunc = createContext();3export const EditTask = createContext();4export const AddNewTask = createContext();5export const ArrForList = createContext();6export const NewInput = createContext();7export const NewUpdate = createContext();8export const NewDoneLine = createContext();9export const ContextImportant = createContext();10export const UpdateLine = createContext();11export const DoneOnly = createContext();12export const CansleObject = createContext();13export const ArrNew = createContext();...
Using AI Code Generation
1import { createContext } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withKnobs } from '@storybook/addon-knobs/react';5import { withContexts } from '@storybook/addon-contexts/react';6import { withTests } from '@storybook/addon-jest';7import { contexts } from './context.js';8import { results } from '../.jest-test-results.json';9import { Button } from '../src/components/Button';10import { ButtonStory } from './ButtonStory';11const context = createContext(contexts);12const stories = storiesOf('Button', module);13 .addDecorator(withKnobs)14 .addDecorator(withTests({ results }))15 .addDecorator(withInfo)16 .addDecorator(withContexts(context));17stories.add('Button', () => <ButtonStory />);
Using AI Code Generation
1import { createContext } from 'storybook-root-decorator';2const { Provider, Consumer } = createContext();3export { Provider, Consumer };4import { Provider, Consumer } from './test.js';5<Provider value={{ state: this.state, setState: this.setState }}>6 {({ state, setState }) => (7 <div>{state.name}</div>8 <div>{state.age}</div>9 <button onClick={() => setState({ name: 'John', age: 20 })}>Click</button>10 )}11import { addDecorator } from '@storybook/react';12import withRootDecorator from 'storybook-root-decorator';13addDecorator(withRootDecorator);14import { addDecorator } from '@storybook/react';15import withRootDecorator from 'storybook-root-decorator';16addDecorator(withRootDecorator);17import { addons } from '@storybook/addons';18import withRootDecorator from 'storybook-root-decorator';19addons.setConfig({20});21const withRootDecorator = require('storybook-root-decorator');22module.exports = (baseConfig, env, defaultConfig) => {23 defaultConfig.module.rules.push(withRootDecorator.module.rules);24 return defaultConfig;25};
Using AI Code Generation
1import { createContext } from 'storybook-root-decorator';2import { addDecorator } from '@storybook/react';3import { ThemeProvider } from 'styled-components';4import { theme } from '@myorg/theme';5const context = createContext();6addDecorator(story => (7 <ThemeProvider theme={theme}>{context.addContext(story)}</ThemeProvider>8));
Using AI Code Generation
1import { createContext } from 'storybook-root-config';2const context = createContext({3});4export default context;5import context from '../test.js';6import { configure } from 'storybook-root-config';7configure(context, module);8import { addDecorator } from 'storybook-root-config';9import { withA11y } from '@storybook/addon-a11y';10addDecorator(withA11y);11import { register } from 'storybook-root-config';12import '@storybook/addon-a11y/register';13register();14import { getWebpackConfig } from 'storybook-root-config';15export default getWebpackConfig();16import { getTsConfig } from 'storybook-root-config';17export default getTsConfig();18import { getManagerConfig } from 'storybook-root-config';19export default getManagerConfig();20import { getManagerHead } from 'storybook-root-config';21export default getManagerHead();22import { getPreviewHead } from 'storybook-root-config';
Using AI Code Generation
1import { createContext } from 'storybook-root-decorator'2const context = createContext({3 context: {4 store: {5 getState: () => ({6 }),7 },8 },9})10context(() => {11 it('should test', () => {12 })13})14import { addDecorator } from '@storybook/react'15import { withRootDecorator } from 'storybook-root-decorator'16addDecorator(withRootDecorator())17import { addDecorator } from '@storybook/react'18import { withRootDecorator } from 'storybook-root-decorator'19addDecorator(withRootDecorator())20import { addDecorator } from '@storybook/react'21import { withRootDecorator } from 'storybook-root-decorator'22addDecorator(withRootDecorator())23import { addDecorator } from '@storybook/react'24import { withRootDecorator } from 'storybook-root-decorator'25addDecorator(withRootDecorator())26import { addDecorator } from '@storybook/react'27import { withRootDecorator } from 'storybook-root-decorator'28addDecorator(withRootDecorator())29import { addDecorator } from '@storybook/react'30import { withRootDecorator } from 'storybook-root-decorator'31addDecorator(withRootDecorator())32import { addDecorator } from '@storybook/react'33import { withRootDecorator } from 'storybook-root-decorator'34addDecorator(withRootDecorator())35import { addDecorator } from '@storybook/react'36import { withRootDecorator } from 'storybook-root-decorator'37addDecorator(withRootDecorator())38import { addDecorator } from '@storybook/react'39import { withRootDecorator } from 'storybook
Using AI Code Generation
1import { createContext } from 'storybook-root-decorator';2const context = createContext();3export const withContext = (storyFn, context) => {4 return storyFn(context);5};6export default {7 parameters: {8 context: {9 }10 }11};12import React from 'react';13import Test from './test';14export const test = () => <Test />;15import React from 'react';16import { render } from '@testing-library/react';17import Test from './test';18describe('Test', () => {19 it('should render successfully', () => {20 const { baseElement } = render(<Test />);21 expect(baseElement).toBeTruthy();22 });23});24import React from 'react';25import Test from './test';26export const test = () => <Test />;27import React from 'react';28import { render } from '@testing-library/react';29import Test from './test';30describe('Test', () => {31 it('should render successfully', () => {32 const { baseElement } = render(<Test />);33 expect(baseElement).toBeTruthy();34 });35});36import React from 'react';37import Test from './test';38export const test = () => <Test />;39import React from 'react';40import { render } from '@testing-library/react';41import Test from './test';42describe('Test', () => {43 it('should render successfully', () => {44 const { baseElement } = render(<Test />);45 expect(baseElement).toBeTruthy();46 });47});48import React from 'react';49import Test from './test';50export const test = () => <Test />;51import React from 'react';52import { render } from '@testing-library/react';53import Test from './test';54describe('Test', () => {55 it('should render successfully', () => {56 const { baseElement } = render(<Test />);57 expect(baseElement).toBeTruthy();58 });59});60import { Meta, Story, Preview }
Using AI Code Generation
1import { createContext } from 'storybook-addon-root-provider';2const MyContext = createContext('MyContext');3<MyContext.Provider value={someValue}>4storiesOf('MyComponent', module)5 .addDecorator(MyContext)6 .add('with some
Using AI Code Generation
1import { createContext } from 'storybook-root-cause';2const context = createContext(3 {4 },5 {6 }7);8const { render } = context;9const { getByText } = render(<div>hello</div>);10getByText('hello');11const customRender = (ui, options) => {12 return {13 };14};15const context = createContext(16 {17 },18 {19 },20);21const { getByText } = context.render(<div>hello</div>);22getByText('hello');23const customRender = (ui, options) => {24 return {25 };26};27const context = createContext(28 {29 },30 {31 },32);33const { getByText } = context.render(<div>hello</div>);34getByText('hello');35const customRender = (ui, options) => {36 return {37 };38};39const context = createContext(40 {41 },42 {43 },44);45const { getByText } = context.render(<div>hello</div>);46getByText('hello');47const customRender = (ui, options) => {48 return {49 };50};51const context = createContext(52 {53 },54 {55 },56);57const { getByText } = context.render(<div>hello</div>);58getByText('hello');59const customRender = (ui, options) => {60 return {61 };62};63const context = createContext(64 {65 },66 {67 },
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!!