How to use DummyContext method in storybook-root

Best JavaScript code snippet using storybook-root

AudioParam-test.js

Source:AudioParam-test.js Github

copy

Full Screen

1var assert = require('assert')2 , _ = require('underscore')3 , AudioParam = require('../build/AudioParam')4 , BLOCK_SIZE = require('../build/constants').BLOCK_SIZE5 , SAMPLE_RATE = 441006 , Ts = 1/SAMPLE_RATE7 , assertAllValuesEqual = require('./helpers')().assertAllValuesEqual8 , assertAllValuesApprox = require('./helpers')().assertAllValuesApprox9 , assertAllValuesFunc = require('./helpers')().assertAllValuesFunc10 , assertApproxEqual = require('./helpers')().assertApproxEqual11describe('AudioParam', function() {12 var dummyContext13 var untilTime = function(audioParam, until, testFunc) {14 var block15 while(audioParam.context.currentTime < until - 3*Ts/2) {16 block = audioParam._tick()17 testFunc(block, dummyContext.currentTime)18 assert.equal(audioParam.value, block.getChannelData(0)[BLOCK_SIZE - 1])19 dummyContext.currentTime += (Ts * BLOCK_SIZE)20 }21 }22 var untilVal = function(audioParam, until, testFunc) {23 var block24 , testUntil = audioParam.value < until ? function(a, b) { return a < b } : function(a, b) { return a < b }25 while(!block || testUntil(block.getChannelData(0)[BLOCK_SIZE - 1], until)) {26 block = audioParam._tick()27 testFunc(block, dummyContext.currentTime)28 assert.equal(audioParam.value, block.getChannelData(0)[BLOCK_SIZE - 1])29 dummyContext.currentTime += (Ts * BLOCK_SIZE)30 }31 }32 var assertValidBlock = function(block) {33 assert.equal(block.length, BLOCK_SIZE)34 assert.equal(block.numberOfChannels, 1)35 }36 beforeEach(function() {37 dummyContext = {currentTime: 0, sampleRate: SAMPLE_RATE}38 })39 it('should set the default value an make it readonly', function() {40 var audioParam = new AudioParam(dummyContext, 98)41 assert.equal(audioParam.defaultValue, 98)42 assert.equal(audioParam.value, 98)43 audioParam.defaultValue = 7744 })45 it('should throw an error if the defaultValue is not a number', function() {46 assert.throws(function() {47 new AudioParam(dummyContext, 'u')48 })49 })50 it('should remove all events when the value is set', function() {51 var audioParam = new AudioParam(dummyContext, 98)52 audioParam._schedule('bla', 9)53 assert.equal(audioParam._scheduled.length, 1)54 audioParam.value = 9955 assert.equal(audioParam._scheduled.length, 0)56 })57 it('should be initialized with constant dsp method', function() {58 var audioParam = new AudioParam(dummyContext, 44)59 , block60 block = audioParam._tick()61 assertValidBlock(block)62 assertAllValuesEqual(block.getChannelData(0), 44)63 block = audioParam._tick()64 assertValidBlock(block)65 assertAllValuesEqual(block.getChannelData(0), 44)66 })67 describe('_geometricSeries', function() {68 it('should progress as expected', function() {69 var audioParam = new AudioParam(dummyContext, 6)70 , iter = audioParam._geometricSeries(1, 2)71 assert.equal(iter(), 2)72 assert.equal(iter(), 4)73 assert.equal(iter(), 8)74 })75 })76 describe('_arithmeticSeries', function() {77 it('should progress as expected', function() {78 var audioParam = new AudioParam(dummyContext, 6)79 , iter = audioParam._arithmeticSeries(1, 2)80 assert.equal(iter(), 3)81 assert.equal(iter(), 5)82 assert.equal(iter(), 7)83 })84 })85 describe('value', function() {86 it('should go to constant value if there aren\'t automation events', function() {87 var audioParam = new AudioParam(dummyContext, 44)88 , block89 block = audioParam._tick()90 assertValidBlock(block)91 assertAllValuesEqual(block.getChannelData(0), 44)92 audioParam.value = 9993 block = audioParam._tick()94 assertValidBlock(block)95 assertAllValuesEqual(block.getChannelData(0), 99)96 })97 })98 describe('setValueAtTime', function() {99 it('should set the value at the time specified', function() {100 var audioParam = new AudioParam(dummyContext, 6)101 , block102 audioParam.setValueAtTime(55, 1)103 // t=0 -> t=~1 / 6104 assert.equal(audioParam.value, 6)105 untilTime(audioParam, 1, function(block) {106 assert.equal(block.length, BLOCK_SIZE)107 assert.equal(block.numberOfChannels, 1)108 assertAllValuesEqual(block.getChannelData(0), 6)109 })110 // t=1 / 55111 dummyContext.currentTime += Ts112 block = audioParam._tick()113 assert.equal(block.length, BLOCK_SIZE)114 assert.equal(block.numberOfChannels, 1)115 assertAllValuesEqual(block.getChannelData(0), 55)116 assert.equal(audioParam.value, 55)117 })118 })119 describe('linearRampToValueAtTime', function() {120 // v(t) = V0 + (V1 - V0) * ((t - T0) / (T1 - T0))121 it('should calculate the ramp for each sample if a-rate', function() {122 var audioParam = new AudioParam(dummyContext, 15, 'a')123 , block124 // Ramp t=0 -> t=1 // 15 -> 25125 audioParam.linearRampToValueAtTime(25, 1)126 assert.equal(audioParam.value, 15)127 untilTime(audioParam, 1, function(block, Tb) {128 assertValidBlock(block)129 assertAllValuesFunc(block.getChannelData(0), Tb, function(t) { return Math.min(15 + 10 * t, 25) })130 })131 // Ramp finished, back to constant132 assert.equal(audioParam._scheduled.length, 1)133 block = audioParam._tick()134 assertValidBlock(block)135 assertAllValuesEqual(block.getChannelData(0), 25)136 assert.equal(audioParam._scheduled.length, 0)137 assert.equal(audioParam.value, 25)138 // Ramp t=1 -> t=3 // 25 -> 20139 dummyContext.currentTime = 1140 audioParam.linearRampToValueAtTime(20, 3)141 untilTime(audioParam, 3, function(block, Tb) {142 assertValidBlock(block)143 assertAllValuesFunc(block.getChannelData(0), Tb, function(t) { return Math.max(25 + -5 * (t - 1) / 2, 20) })144 })145 // Ramp finished, back to constant146 assert.equal(audioParam._scheduled.length, 1)147 block = audioParam._tick()148 assertValidBlock(block)149 assertAllValuesEqual(block.getChannelData(0), 20)150 assert.equal(audioParam._scheduled.length, 0)151 assert.equal(audioParam.value, 20)152 })153 it('should calculate the ramp for whole block if k-rate', function() {154 var audioParam = new AudioParam(dummyContext, 15, 'k')155 , block156 // Ramp t=0 -> t=1 // 15 -> 25157 audioParam.linearRampToValueAtTime(25, 1)158 assert.equal(audioParam.value, 15)159 untilTime(audioParam, 1 - 3*Ts/2, function(block, Tb) {160 assertValidBlock(block)161 assertAllValuesApprox(block.getChannelData(0), 15 + 10 * Tb)162 })163 // Ramp finished, back to constant164 assert.equal(audioParam._scheduled.length, 1)165 block = audioParam._tick()166 assertValidBlock(block)167 assertAllValuesEqual(block.getChannelData(0), 25)168 assert.equal(audioParam._scheduled.length, 0)169 assert.equal(audioParam.value, 25)170 // Ramp t=1 -> t=3 // 25 -> 20171 dummyContext.currentTime = 1172 audioParam.linearRampToValueAtTime(20, 3)173 untilTime(audioParam, 3 - 3*Ts/2, function(block, Tb) {174 assertValidBlock(block)175 assertAllValuesApprox(block.getChannelData(0), 25 + -5 * (Tb - 1) / 2)176 })177 // Ramp finished, back to constant178 assert.equal(audioParam._scheduled.length, 1)179 block = audioParam._tick()180 assertValidBlock(block)181 assertAllValuesEqual(block.getChannelData(0), 20)182 assert.equal(audioParam._scheduled.length, 0)183 assert.equal(audioParam.value, 20)184 })185 })186 describe('exponentialRampToValueAtTime', function() {187 // v(t) = V0 * (V1 / V0) ^ ((t - T0) / (T1 - T0))188 it('should throw an error if value is <= 0', function() {189 var audioParam = new AudioParam(dummyContext, 15, 'a')190 assert.throws(function() {191 audioParam.exponentialRampToValueAtTime(-1, 9)192 })193 assert.throws(function() {194 audioParam.exponentialRampToValueAtTime(0, 1)195 })196 audioParam.value = -5197 assert.throws(function() {198 audioParam.exponentialRampToValueAtTime(10, 9)199 })200 })201 it('should calculate the ramp for each sample if a-rate', function() {202 var audioParam = new AudioParam(dummyContext, 1, 'a')203 , block204 // Ramp t=0 -> t=1 // 1 -> 2205 audioParam.exponentialRampToValueAtTime(2, 1)206 assert.equal(audioParam.value, 1)207 untilTime(audioParam, 1, function(block, Tb) {208 assertValidBlock(block)209 assertAllValuesFunc(block.getChannelData(0), Tb, function(t) { return Math.min(Math.pow(2, t), 2) })210 })211 // Ramp finished, back to constant212 assert.equal(audioParam._scheduled.length, 1)213 block = audioParam._tick()214 assertValidBlock(block)215 assertAllValuesEqual(block.getChannelData(0), 2)216 assert.equal(audioParam._scheduled.length, 0)217 assert.equal(audioParam.value, 2)218 // Ramp t=1 -> t=3 // 10 -> 5219 audioParam.value = 10220 dummyContext.currentTime = 1221 audioParam.exponentialRampToValueAtTime(5, 3)222 untilTime(audioParam, 3, function(block, Tb) {223 assertValidBlock(block)224 assertAllValuesFunc(block.getChannelData(0), Tb, function(t) { return Math.max(10 * Math.pow(0.5, (t - 1) / 2), 5) })225 })226 // Ramp finished, back to constant227 assert.equal(audioParam._scheduled.length, 1)228 block = audioParam._tick()229 assertValidBlock(block)230 assertAllValuesEqual(block.getChannelData(0), 5)231 assert.equal(audioParam._scheduled.length, 0)232 assert.equal(audioParam.value, 5)233 })234 it('should calculate the ramp for the whole block if k-rate', function() {235 var audioParam = new AudioParam(dummyContext, 1, 'k')236 , block237 // Ramp t=0 -> t=1 // 1 -> 2238 audioParam.exponentialRampToValueAtTime(2, 1)239 assert.equal(audioParam.value, 1)240 untilTime(audioParam, 1, function(block, Tb) {241 assertValidBlock(block)242 assertAllValuesApprox(block.getChannelData(0), Math.pow(2, Tb))243 })244 // Ramp finished, back to constant245 assert.equal(audioParam._scheduled.length, 1)246 block = audioParam._tick()247 assertValidBlock(block)248 assertAllValuesEqual(block.getChannelData(0), 2)249 assert.equal(audioParam._scheduled.length, 0)250 assert.equal(audioParam.value, 2)251 // Ramp t=1 -> t=3 // 10 -> 5252 audioParam.value = 10253 dummyContext.currentTime = 1254 audioParam.exponentialRampToValueAtTime(5, 3)255 untilTime(audioParam, 3, function(block, Tb) {256 assertValidBlock(block)257 assertAllValuesApprox(block.getChannelData(0), 10 * Math.pow(0.5, (Tb - 1) / 2))258 })259 // Ramp finished, back to constant260 assert.equal(audioParam._scheduled.length, 1)261 block = audioParam._tick()262 assertValidBlock(block)263 assertAllValuesEqual(block.getChannelData(0), 5)264 assert.equal(audioParam._scheduled.length, 0)265 assert.equal(audioParam.value, 5)266 })267 })268 describe('setTargetAtTime', function() {269 // V1 + (V0 - V1) * exp(-(t - T0) / timeConstant)270 it('should calculate the ramp for each sample if a-rate', function() {271 var audioParam = new AudioParam(dummyContext, 1, 'a')272 , block273 // t=0 -> t=1 // 1274 dummyContext.currentTime = 1275 // Ramp t=1 -> ... // 1 -> 2276 audioParam.setTargetAtTime(2, 1, 0.3)277 assert.equal(audioParam.value, 1)278 untilVal(audioParam, 2, function(block, Tb) {279 assertValidBlock(block)280 assertAllValuesFunc(block.getChannelData(0), Tb, function(t) { return Math.min(2 + -Math.exp(-(t - 1) / 0.3), 2) })281 })282 // Ramp finished, back to constant283 block = audioParam._tick()284 assertValidBlock(block)285 assertAllValuesEqual(block.getChannelData(0), 2)286 assert.equal(audioParam._scheduled.length, 0)287 assert.equal(audioParam.value, 2)288 // Ramp t=2 -> ... // 10 -> 5289 dummyContext.currentTime = 2290 audioParam.value = 10291 audioParam.setTargetAtTime(5, 2, 0.15)292 untilVal(audioParam, 5, function(block, Tb) {293 assertValidBlock(block)294 assertAllValuesFunc(block.getChannelData(0), Tb, function(t) { return Math.max(5 + 5 * Math.exp(-(t - 2) / 0.15), 5) })295 })296 })297 it('should calculate the ramp for the whole block if k-rate', function() {298 var audioParam = new AudioParam(dummyContext, 1, 'k')299 , block300 // t=0 -> t=1 // 1301 dummyContext.currentTime = 1302 // Ramp t=1 -> ... // 1 -> 2303 audioParam.setTargetAtTime(2, 1, 0.3)304 assert.equal(audioParam.value, 1)305 untilVal(audioParam, 2, function(block, Tb) {306 assertValidBlock(block)307 assertAllValuesApprox(block.getChannelData(0), 2 + -Math.exp(-(Tb - 1) / 0.3))308 })309 // Ramp finished, back to constant310 block = audioParam._tick()311 assertValidBlock(block)312 assertAllValuesEqual(block.getChannelData(0), 2)313 assert.equal(audioParam._scheduled.length, 0)314 assert.equal(audioParam.value, 2)315 // Ramp t=2 -> ... // 10 -> 5316 dummyContext.currentTime = 2317 audioParam.value = 10318 audioParam.setTargetAtTime(5, 2, 0.66)319 untilVal(audioParam, 5, function(block, Tb) {320 assertValidBlock(block)321 assertAllValuesApprox(block.getChannelData(0), 5 + 5 * Math.exp(-(Tb - 2) / 0.15))322 })323 })324 })325 describe('setValueCurveAtTime', function() {326 // V1 + (V0 - V1) * exp(-(t - T0) / timeConstant)327 it('should calculate the values for each sample if a-rate', function() {328 var audioParam = new AudioParam(dummyContext, 1, 'a')329 , t1 = 12800 / 10 * Ts330 , t2 = t1 + 12800 / 5 * Ts331 , t3 = t2 + 12800 / 5 * Ts332 , t4 = t3 + 12800 / 5 * Ts333 , t5 = t4 + (12800 / 10 + 12800 / 5) * Ts334 , block335 // Ramp t=0336 audioParam.setValueCurveAtTime([1, 2, 3, 4, 5], 0, 12800 * Ts)337 assert.equal(audioParam.value, 1)338 untilTime(audioParam, t1, function(block, Tb) {339 assertValidBlock(block)340 assertAllValuesEqual(block.getChannelData(0), 1)341 })342 untilTime(audioParam, t2, function(block, Tb) {343 assertValidBlock(block)344 assertAllValuesEqual(block.getChannelData(0), 2)345 })346 untilTime(audioParam, t3, function(block, Tb) {347 assertValidBlock(block)348 assertAllValuesEqual(block.getChannelData(0), 3)349 })350 untilTime(audioParam, t4, function(block, Tb) {351 assertValidBlock(block)352 assertAllValuesEqual(block.getChannelData(0), 4)353 })354 untilTime(audioParam, t5, function(block, Tb) {355 assertValidBlock(block)356 assertAllValuesEqual(block.getChannelData(0), 5)357 })358 // Ramp finished, back to constant359 block = audioParam._tick()360 assertValidBlock(block)361 assertAllValuesEqual(block.getChannelData(0), 5)362 assert.equal(audioParam._scheduled.length, 0)363 assert.equal(audioParam.value, 5)364 })365 it('should calculate the values for the whole block if k-rate', function() {366 var audioParam = new AudioParam(dummyContext, 1, 'k')367 , block368 // Ramp t=0369 audioParam.setValueCurveAtTime([1, 2, 3, 4, 5], 0, 10000 * Ts)370 assert.equal(audioParam.value, 1)371 untilTime(audioParam, 1000 * Ts, function(block, Tb) {372 assertValidBlock(block)373 assertAllValuesEqual(block.getChannelData(0), 1)374 })375 untilTime(audioParam, 3000 * Ts, function(block, Tb) {376 assertValidBlock(block)377 assertAllValuesEqual(block.getChannelData(0), 2)378 })379 untilTime(audioParam, 5000 * Ts, function(block, Tb) {380 assertValidBlock(block)381 assertAllValuesEqual(block.getChannelData(0), 3)382 })383 untilTime(audioParam, 7000 * Ts, function(block, Tb) {384 assertValidBlock(block)385 assertAllValuesEqual(block.getChannelData(0), 4)386 })387 untilTime(audioParam, 1000 * Ts, function(block, Tb) {388 assertValidBlock(block)389 assertAllValuesEqual(block.getChannelData(0), 5)390 })391 // Ramp finished, back to constant392 block = audioParam._tick()393 assertValidBlock(block)394 assertAllValuesEqual(block.getChannelData(0), 5)395 assert.equal(audioParam._scheduled.length, 0)396 assert.equal(audioParam.value, 5)397 })398 })399 describe('events sequence', function() {400 it('should start a ramp only after a setValue', function() {401 var audioParam = new AudioParam(dummyContext, -1, 'a')402 , block403 audioParam.setValueAtTime(0, 2)404 audioParam.linearRampToValueAtTime(1, 3)405 // expected:406 // t=0 -> t=2 / -1407 // t=2 / 0408 // t=2 -> t=3 / 0 -> 1409 untilTime(audioParam, 2, function(block) {410 assertValidBlock(block)411 assertAllValuesEqual(block.getChannelData(0), -1)412 })413 var T0 = audioParam.context.currentTime414 untilTime(audioParam, 3, function(block, Tb) {415 assertValidBlock(block)416 assertAllValuesFunc(block.getChannelData(0), Tb, function(t) { return Math.min((t - T0) / (3 - T0), 1) })417 })418 })419 })...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

1// @flow2import { InvalidArgumentError, ObjectNotFoundError } from 'errors';3import { dummyContentItemData as dummyData } from 'lib/testResources';4import * as m from '../../model';5import lib from '..';6describe(`convertContextToSuperContext`, (): void => {7 let dummyParagraph22: m.ParagraphContentItem;8 let dummyParagraph21: m.ParagraphContentItem;9 let dummyHeading2: m.HeadingContentItem;10 let dummyParagraph12: m.ParagraphContentItem;11 let dummyParagraph11: m.ParagraphContentItem;12 let dummyHeading1: m.HeadingContentItem;13 let dummyRoot: m.RootContentItem;14 let dummyContentItemsById: m.ContentItemsById;15 beforeEach((): void => {16 dummyParagraph22 = { ...dummyData.paragraphContentItem4 };17 dummyParagraph21 = { ...dummyData.paragraphContentItem3 };18 dummyHeading2 = {19 ...dummyData.headingContentItem2,20 subItemIds: [dummyParagraph21.id, dummyParagraph22.id],21 };22 dummyParagraph12 = { ...dummyData.paragraphContentItem2 };23 dummyParagraph11 = { ...dummyData.paragraphContentItem };24 dummyHeading1 = {25 ...dummyData.headingContentItem,26 subItemIds: [dummyParagraph11.id, dummyParagraph12.id],27 };28 dummyRoot = {29 ...dummyData.rootContentItem,30 subItemIds: [dummyHeading1.id, dummyHeading2.id],31 };32 dummyContentItemsById = {33 [dummyRoot.id]: dummyRoot,34 [dummyHeading1.id]: dummyHeading1,35 [dummyParagraph11.id]: dummyParagraph11,36 [dummyParagraph12.id]: dummyParagraph12,37 [dummyHeading2.id]: dummyHeading2,38 [dummyParagraph21.id]: dummyParagraph21,39 [dummyParagraph22.id]: dummyParagraph22,40 };41 });42 it(`returns the correct SuperContext, when the passed context is a SiblingContext`, (): void => {43 const dummyContext: m.SiblingContext = {44 contextType: m.contextTypes.SIBLING,45 contextItemId: dummyParagraph11.id,46 };47 const actualResult = lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);48 const expectedResult: m.ExtendedSuperContext = {49 contextType: m.contextTypes.SUPER,50 contextItemId: dummyHeading1.id,51 indexInSiblingItems: 1,52 siblingItemIds: dummyHeading1.subItemIds,53 };54 expect(actualResult).toStrictEqual(expectedResult);55 });56 it(`returns the correct SuperContext, when the passed context is a SiblingContext and indexInSiblingItemsShift is 0`, (): void => {57 const dummyContext: m.SiblingContext = {58 contextType: m.contextTypes.SIBLING,59 contextItemId: dummyParagraph12.id,60 indexInSiblingItemsShift: 0,61 };62 const actualResult = lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);63 const expectedResult: m.ExtendedSuperContext = {64 contextType: m.contextTypes.SUPER,65 contextItemId: dummyHeading1.id,66 indexInSiblingItems: 2,67 siblingItemIds: dummyHeading1.subItemIds,68 };69 expect(actualResult).toStrictEqual(expectedResult);70 });71 it(`returns the correct SuperContext, when the passed context is a SiblingContext and indexInSiblingItemsShift is a positive number different from 0`, (): void => {72 const dummyContext: m.SiblingContext = {73 contextType: m.contextTypes.SIBLING,74 contextItemId: dummyParagraph11.id,75 indexInSiblingItemsShift: 1,76 };77 const actualResult = lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);78 const expectedResult: m.ExtendedSuperContext = {79 contextType: m.contextTypes.SUPER,80 contextItemId: dummyHeading1.id,81 indexInSiblingItems: 2,82 siblingItemIds: dummyHeading1.subItemIds,83 };84 expect(actualResult).toStrictEqual(expectedResult);85 });86 it(`returns the correct SuperContext, when the passed context is a SiblingContext and indexInSiblingItemsShift is a negative number`, (): void => {87 const dummyContext: m.SiblingContext = {88 contextType: m.contextTypes.SIBLING,89 contextItemId: dummyParagraph12.id,90 indexInSiblingItemsShift: -2,91 };92 const actualResult = lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);93 const expectedResult: m.ExtendedSuperContext = {94 contextType: m.contextTypes.SUPER,95 contextItemId: dummyHeading1.id,96 indexInSiblingItems: 0,97 siblingItemIds: dummyHeading1.subItemIds,98 };99 expect(actualResult).toStrictEqual(expectedResult);100 });101 it(`returns the passed context unchanged, when the passed context already is a SuperContext`, (): void => {102 const dummyContext: m.SuperContext = {103 contextType: m.contextTypes.SUPER,104 contextItemId: dummyRoot.id,105 };106 const actualResult = lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);107 expect(actualResult).toBe(dummyContext);108 });109 it(`returns NULL, when the passed context is NULL`, (): void => {110 const actualResult = lib.convertContextToSuperContext(null, dummyContentItemsById);111 expect(actualResult).toBeNull();112 });113 it(`throws an ObjectNotFoundError, when the contentItem with id contextItemId could not be found`, (): void => {114 const dummyContext: m.SiblingContext = {115 contextType: m.contextTypes.SIBLING,116 contextItemId: 'DefinitelyNotValidId',117 };118 expect((): void => {119 lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);120 }).toThrow(ObjectNotFoundError);121 });122 it(`throws an InvalidArgumentError, when the calculated indexInSiblingItems is less than 0`, (): void => {123 const dummyContext: m.SiblingContext = {124 contextType: m.contextTypes.SIBLING,125 contextItemId: dummyParagraph12.id,126 indexInSiblingItemsShift: -3,127 };128 expect((): void => {129 lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);130 }).toThrow(InvalidArgumentError);131 });132 it(`throws an InvalidArgumentError, when the calculated indexInSiblingItems i greater than the length of the siblingItemIds array`, (): void => {133 const dummyContext: m.SiblingContext = {134 contextType: m.contextTypes.SIBLING,135 contextItemId: dummyParagraph12.id,136 indexInSiblingItemsShift: 1,137 };138 expect((): void => {139 lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);140 }).toThrow(InvalidArgumentError);141 });142 it(`throws an InvalidArgumentError, when the passed context is a SiblingContext and the contextItem does not have a superItem`, (): void => {143 const dummyContext: m.SiblingContext = {144 contextType: m.contextTypes.SIBLING,145 contextItemId: dummyRoot.id,146 };147 expect((): void => {148 lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);149 }).toThrow(InvalidArgumentError);150 });151 it(`throws an InvalidArgumentError, when the contextType is invalid`, (): void => {152 const dummyContext: any = {153 contextType: 'INVALID_CONTEXT_TYPE',154 contextItemId: dummyParagraph12.id,155 };156 expect((): void => {157 lib.convertContextToSuperContext(dummyContext, dummyContentItemsById);158 }).toThrow(InvalidArgumentError);159 });...

Full Screen

Full Screen

dummy_canvas.js

Source:dummy_canvas.js Github

copy

Full Screen

1function DummyCanvas() {2 this._context = new DummyContext();3}4DummyCanvas.prototype.getContext = function() {5 return this._context;6};7function DummyContext() {8 this.fillColor = 'black';9}10DummyContext.prototype.fillRect = function(x, y, width, height) {11};12DummyContext.prototype.rect = function(x, y, width, height) {13};14DummyContext.prototype.clip = function() {15};16DummyContext.prototype.save = function() {17};18DummyContext.prototype.restore = function() {19};20DummyContext.prototype.scale = function(x, y) {21};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { withDummyContext } from 'storybook-root-decorator';5import Button from './Button';6storiesOf('Button', module)7 .addDecorator(withDummyContext)8 .add('with text', () => (9 <Button onClick={action('clicked')}>Hello Button</Button>10 .add('with some emoji', () => (11 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>12 ));

Full Screen

Using AI Code Generation

copy

Full Screen

1import {DummyContext} from 'storybook-root';2import React from 'react';3import {render} from 'react-dom';4import App from './App';5render(6 document.getElementById('root')7);8import React from 'react';9import {useDummyContext} from 'storybook-root';10export default function App() {11 const {dummy, setDummy} = useDummyContext();12 return (13 <p>{dummy}</p>14 <button onClick={() => setDummy(dummy + 1)}>Click Me</button>15 );16}17### `useDummyContext()`18MIT © [Michele Bertoli](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { DummyContext } from "storybook-root";2import { withDummyContext } from "storybook-root";3import { withDummyContext } from "storybook-root";4import { DummyContext } from "storybook-root";5import { withDummyContext } from "storybook-root";6import { withDummyContext } from "storybook-root";7import React from "react";8import { render } from "react-testing-library";9import { DummyContext } from "storybook-root";10const TestComponent = () => {11 const { dummyContext } = React.useContext(DummyContext);12 return <div>{dummyContext}</div>;13};14describe("TestComponent", () => {15 it("should render dummyContext", () => {16 const { getByText } = render(17 );18 expect(getByText("dummyContext")).toBeInTheDocument();19 });20});21import React from "react";22import { render } from "react-testing-library";23import { withDummyContext } from "storybook-root";24const TestComponent = ({ dummyContext }) => <div>{dummyContext}</div>;25const TestComponentWithDummyContext = withDummyContext(TestComponent);26describe("TestComponentWithDummyContext", () => {27 it("should render dummyContext", () => {28 const { getByText } = render(29 );30 expect(getByText("dummyContext")).toBeInTheDocument();31 });32});33import React from "react";34import { render } from "react-testing-library";35import { withDummyContext } from "storybook-root";36const TestComponent = ({ dummyContext }) => <div>{dummyContext}</div

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