How to use sinon.fake method in sinon

Best JavaScript code snippet using sinon

new_platform.karma_mock.js

Source:new_platform.karma_mock.js Github

copy

Full Screen

...69 };70 return defaultValues[item] || defaultValue;71 },72 getUpdate$: () => ({73 subscribe: sinon.fake(),74 }),75 isDefault: sinon.fake(),76};77const mockCoreSetup = {78 chrome: {},79 http: {80 basePath: {81 get: sinon.fake.returns(''),82 },83 },84 injectedMetadata: {},85 uiSettings: mockUiSettings,86};87const mockCoreStart = {88 application: {89 capabilities: {},90 },91 chrome: {92 overlays: {93 openModal: sinon.fake(),94 },95 },96 http: {97 basePath: {98 get: sinon.fake.returns(''),99 },100 },101 notifications: {102 toasts: {},103 },104 i18n: {},105 overlays: {},106 savedObjects: {107 client: {},108 },109 uiSettings: mockUiSettings,110};111const querySetup = {112 state$: mockObservable(),113 filterManager: {114 getFetches$: sinon.fake(),115 getFilters: sinon.fake(),116 getAppFilters: sinon.fake(),117 getGlobalFilters: sinon.fake(),118 removeFilter: sinon.fake(),119 addFilters: sinon.fake(),120 setFilters: sinon.fake(),121 removeAll: sinon.fake(),122 getUpdates$: mockObservable,123 },124 timefilter: {125 timefilter: {126 getFetch$: mockObservable,127 getAutoRefreshFetch$: mockObservable,128 getEnabledUpdated$: mockObservable,129 getTimeUpdate$: mockObservable,130 getRefreshIntervalUpdate$: mockObservable,131 isTimeRangeSelectorEnabled: () => {132 return isTimeRangeSelectorEnabled;133 },134 isAutoRefreshSelectorEnabled: () => {135 return isAutoRefreshSelectorEnabled;136 },137 disableAutoRefreshSelector: () => {138 isAutoRefreshSelectorEnabled = false;139 },140 enableAutoRefreshSelector: () => {141 isAutoRefreshSelectorEnabled = true;142 },143 getRefreshInterval: () => {144 return refreshInterval;145 },146 setRefreshInterval: (interval) => {147 refreshInterval = interval;148 },149 enableTimeRangeSelector: () => {150 isTimeRangeSelectorEnabled = true;151 },152 disableTimeRangeSelector: () => {153 isTimeRangeSelectorEnabled = false;154 },155 getTime: sinon.fake(),156 setTime: sinon.fake(),157 getActiveBounds: sinon.fake(),158 getBounds: sinon.fake(),159 calculateBounds: sinon.fake(),160 createFilter: sinon.fake(),161 },162 history: sinon.fake(),163 },164 savedQueries: {165 saveQuery: sinon.fake(),166 getAllSavedQueries: sinon.fake(),167 findSavedQueries: sinon.fake(),168 getSavedQuery: sinon.fake(),169 deleteSavedQuery: sinon.fake(),170 getSavedQueryCount: sinon.fake(),171 },172};173const mockAggTypesRegistry = () => {174 const registry = new AggTypesRegistry();175 const registrySetup = registry.setup();176 const aggTypes = getAggTypes({177 uiSettings: mockCoreSetup.uiSettings,178 query: querySetup,179 getInternalStartServices: () => ({180 fieldFormats: getFieldFormatsRegistry(mockCoreStart),181 notifications: mockCoreStart.notifications,182 }),183 });184 aggTypes.buckets.forEach((type) => registrySetup.registerBucket(type));185 aggTypes.metrics.forEach((type) => registrySetup.registerMetric(type));186 return registry;187};188const aggTypesRegistry = mockAggTypesRegistry();189export const npSetup = {190 core: mockCoreSetup,191 plugins: {192 advancedSettings: {193 component: {194 register: sinon.fake(),195 componentType: ComponentRegistry.componentType,196 },197 },198 usageCollection: {199 allowTrackUserAgent: sinon.fake(),200 reportUiStats: sinon.fake(),201 METRIC_TYPE,202 },203 embeddable: {204 registerEmbeddableFactory: sinon.fake(),205 },206 expressions: {207 registerFunction: sinon.fake(),208 registerRenderer: sinon.fake(),209 registerType: sinon.fake(),210 __LEGACY: {211 renderers: {212 register: () => undefined,213 get: () => null,214 },215 getExecutor: () => ({216 interpreter: {217 interpretAst: () => {},218 },219 }),220 },221 },222 data: {223 autocomplete: {224 addProvider: sinon.fake(),225 getProvider: sinon.fake(),226 },227 query: querySetup,228 search: {229 aggs: {230 calculateAutoTimeExpression: sinon.fake(),231 types: aggTypesRegistry.setup(),232 },233 __LEGACY: {234 esClient: {235 search: sinon.fake(),236 msearch: sinon.fake(),237 },238 },239 },240 fieldFormats: getFieldFormatsRegistry(mockCoreSetup),241 },242 share: {243 register: () => {},244 urlGenerators: {245 registerUrlGenerator: () => {},246 },247 },248 devTools: {249 register: () => {},250 },251 kibanaLegacy: {252 registerLegacyApp: () => {},253 forwardApp: () => {},254 config: {255 defaultAppId: 'home',256 },257 },258 inspector: {259 registerView: () => undefined,260 __LEGACY: {261 views: {262 register: () => undefined,263 },264 },265 },266 uiActions: {267 attachAction: sinon.fake(),268 registerAction: sinon.fake(),269 registerTrigger: sinon.fake(),270 },271 home: {272 featureCatalogue: {273 register: sinon.fake(),274 },275 environment: {276 update: sinon.fake(),277 },278 config: {279 disableWelcomeScreen: false,280 },281 tutorials: {282 setVariable: sinon.fake(),283 },284 },285 charts: {286 theme: {287 chartsTheme$: mockObservable,288 useChartsTheme: sinon.fake(),289 },290 colors: {291 seedColors: ['white', 'black'],292 },293 },294 management: {295 sections: {296 getSection: () => ({297 registerApp: sinon.fake(),298 }),299 },300 },301 indexPatternManagement: {302 list: { addListConfig: sinon.fake() },303 creation: { addCreationConfig: sinon.fake() },304 },305 discover: {306 docViews: {307 addDocView: sinon.fake(),308 setAngularInjectorGetter: sinon.fake(),309 },310 },311 visTypeVega: {312 config: sinon.fake(),313 },314 visualizations: {315 createBaseVisualization: sinon.fake(),316 createReactVisualization: sinon.fake(),317 registerAlias: sinon.fake(),318 hideTypes: sinon.fake(),319 },320 mapsLegacy: {321 serviceSettings: sinon.fake(),322 getPrecision: sinon.fake(),323 getZoomPrecision: sinon.fake(),324 },325 },326};327export const npStart = {328 core: mockCoreStart,329 plugins: {330 management: {331 legacy: {332 getSection: () => ({333 register: sinon.fake(),334 deregister: sinon.fake(),335 hasItem: sinon.fake(),336 }),337 },338 sections: {339 getSection: () => ({340 registerApp: sinon.fake(),341 }),342 },343 },344 indexPatternManagement: {345 list: {346 getType: sinon.fake(),347 getIndexPatternCreationOptions: sinon.fake(),348 },349 creation: {350 getIndexPatternTags: sinon.fake(),351 getFieldInfo: sinon.fake(),352 areScriptedFieldsEnabled: sinon.fake(),353 },354 },355 embeddable: {356 getEmbeddableFactory: sinon.fake(),357 getEmbeddableFactories: sinon.fake(),358 registerEmbeddableFactory: sinon.fake(),359 },360 expressions: {361 registerFunction: sinon.fake(),362 registerRenderer: sinon.fake(),363 registerType: sinon.fake(),364 },365 kibanaLegacy: {366 getForwards: () => [],367 loadFontAwesome: () => {},368 config: {369 defaultAppId: 'home',370 },371 dashboardConfig: {372 turnHideWriteControlsOn: sinon.fake(),373 getHideWriteControls: sinon.fake(),374 },375 },376 dashboard: {377 getSavedDashboardLoader: sinon.fake(),378 },379 data: {380 actions: {381 createFiltersFromValueClickAction: Promise.resolve(['yes']),382 createFiltersFromRangeSelectAction: sinon.fake(),383 },384 autocomplete: {385 getProvider: sinon.fake(),386 },387 getSuggestions: sinon.fake(),388 indexPatterns: {389 get: sinon.spy((indexPatternId) =>390 Promise.resolve({391 id: indexPatternId,392 isTimeNanosBased: () => false,393 popularizeField: () => {},394 })395 ),396 },397 ui: {398 IndexPatternSelect: mockComponent,399 SearchBar: mockComponent,400 },401 query: {402 filterManager: {403 getFetches$: sinon.fake(),404 getFilters: sinon.fake(),405 getAppFilters: sinon.fake(),406 getGlobalFilters: sinon.fake(),407 removeFilter: sinon.fake(),408 addFilters: sinon.fake(),409 setFilters: sinon.fake(),410 removeAll: sinon.fake(),411 getUpdates$: mockObservable,412 },413 timefilter: {414 timefilter: {415 getFetch$: mockObservable,416 getAutoRefreshFetch$: mockObservable,417 getEnabledUpdated$: mockObservable,418 getTimeUpdate$: mockObservable,419 getRefreshIntervalUpdate$: mockObservable,420 isTimeRangeSelectorEnabled: () => {421 return isTimeRangeSelectorEnabled;422 },423 isAutoRefreshSelectorEnabled: () => {424 return isAutoRefreshSelectorEnabled;425 },426 disableAutoRefreshSelector: () => {427 isAutoRefreshSelectorEnabled = false;428 },429 enableAutoRefreshSelector: () => {430 isAutoRefreshSelectorEnabled = true;431 },432 getRefreshInterval: () => {433 return refreshInterval;434 },435 setRefreshInterval: (interval) => {436 refreshInterval = interval;437 },438 enableTimeRangeSelector: () => {439 isTimeRangeSelectorEnabled = true;440 },441 disableTimeRangeSelector: () => {442 isTimeRangeSelectorEnabled = false;443 },444 getTime: sinon.fake(),445 setTime: sinon.fake(),446 getActiveBounds: sinon.fake(),447 getBounds: sinon.fake(),448 calculateBounds: sinon.fake(),449 createFilter: sinon.fake(),450 },451 history: sinon.fake(),452 },453 },454 search: {455 aggs: {456 calculateAutoTimeExpression: sinon.fake(),457 createAggConfigs: (indexPattern, configStates = []) => {458 return new AggConfigs(indexPattern, configStates, {459 typesRegistry: aggTypesRegistry.start(),460 fieldFormats: getFieldFormatsRegistry(mockCoreStart),461 });462 },463 types: aggTypesRegistry.start(),464 },465 __LEGACY: {466 esClient: {467 search: sinon.fake(),468 msearch: sinon.fake(),469 },470 },471 },472 fieldFormats: getFieldFormatsRegistry(mockCoreStart),473 },474 share: {475 toggleShareContextMenu: () => {},476 },477 inspector: {478 isAvailable: () => false,479 open: () => ({480 onClose: Promise.resolve(undefined),481 close: () => Promise.resolve(undefined),482 }),483 },484 uiActions: {485 attachAction: sinon.fake(),486 registerAction: sinon.fake(),487 registerTrigger: sinon.fake(),488 detachAction: sinon.fake(),489 executeTriggerActions: sinon.fake(),490 getTrigger: sinon.fake(),491 getTriggerActions: sinon.fake(),492 getTriggerCompatibleActions: sinon.fake(),493 },494 visualizations: {495 get: sinon.fake(),496 all: sinon.fake(),497 getAliases: sinon.fake(),498 savedVisualizationsLoader: {},499 showNewVisModal: sinon.fake(),500 createVis: sinon.fake(),501 convertFromSerializedVis: sinon.fake(),502 convertToSerializedVis: sinon.fake(),503 },504 navigation: {505 ui: {506 TopNavMenu: mockComponent,507 },508 },509 charts: {510 theme: {511 chartsTheme$: mockObservable,512 useChartsTheme: sinon.fake(),513 },514 },515 discover: {516 docViews: {517 DocViewer: () => null,518 },519 savedSearchLoader: {},520 },521 },522};523export function __setup__(coreSetup) {524 npSetup.core = coreSetup;525 // no-op application register calls (this is overwritten to526 // bootstrap an LP plugin outside of tests)...

Full Screen

Full Screen

test.discover-task-accordion.js

Source:test.discover-task-accordion.js Github

copy

Full Screen

...11/* eslint-disable-next-line no-undef */12describe('discover-task-accordion actions', () => {13 /* eslint-disable-next-line no-undef */14 it('try TASK_BUTTON#SAVE and it should be true', () => {15 const testFn = sinon.fake(actions['TASK_BUTTON#SAVE'].effect)16 testFn()17 assert.equal(testFn.callCount, 1)18 })19 /* eslint-disable-next-line no-undef */20 it('try TASK_USERS#SEARCH and it should be true', () => {21 const testFn = sinon.fake(actions['TASK_USERS#SEARCH'].effect)22 testFn()23 assert.equal(testFn.callCount, 1)24 })25 /* eslint-disable-next-line no-undef */26 it('try TASK_USERS_SEARCH_REQUESTED and it should be true', () => {27 const testFn = sinon.fake(actions.TASK_USERS_SEARCH_REQUESTED)28 testFn({29 action: { payload: { value: 'test' } },30 dispatch: sinon.fake(),31 updateProperties: sinon.fake(),32 properties: {}33 })34 assert.equal(testFn.callCount, 1)35 })36 /* eslint-disable-next-line no-undef */37 it('try TASK_BUTTON_SAVE_SUCCESS and it should be true', () => {38 const testFn = sinon.fake(actions.TASK_BUTTON_SAVE_SUCCESS)39 testFn({40 action: { value: 'test' },41 dispatch: sinon.fake(),42 updateState: sinon.fake(),43 properties: {}44 })45 assert.equal(testFn.callCount, 1)46 })47 /* eslint-disable-next-line no-undef */48 it('try TASK_USERS_SEARCH_SUCCESS and it should be true', () => {49 const testFn = sinon.fake(actions.TASK_USERS_SEARCH_SUCCESS)50 testFn({51 action: { payload: { result: [] } },52 dispatch: sinon.fake(),53 updateState: sinon.fake(),54 properties: {}55 })56 assert.equal(testFn.callCount, 1)57 })58 /* eslint-disable-next-line no-undef */59 it('try NOW_ACCORDION_ITEM#CLICKED and it should be true', () => {60 const testFn = sinon.fake(actions['NOW_ACCORDION_ITEM#CLICKED'])61 testFn({62 action: { result: 'test' },63 dispatch: sinon.fake(),64 updateState: sinon.fake(),65 properties: {},66 state: { selectedTask: {} }67 })68 assert.equal(testFn.callCount, 1)69 })70 /* eslint-disable-next-line no-undef */71 it('try SAVE_BUTTON_WATCHED and it should be true', () => {72 const testFn = sinon.fake(actions.SAVE_BUTTON_WATCHED)73 testFn({74 action: { result: 'test' },75 dispatch: sinon.fake(),76 updateState: sinon.fake(),77 properties: {},78 state: { selectedTask: { status: { value: '' } }, selectedTaskClean: {} }79 })80 assert.equal(testFn.callCount, 1)81 })82 /* eslint-disable-next-line no-undef */83 it('try SAVE_BUTTON_UPDATE_REQUEST and it should be true', () => {84 const testFn = sinon.fake(actions.SAVE_BUTTON_UPDATE_REQUEST)85 testFn({86 action: { payload: { path: 'test', value: 'test' } },87 dispatch: sinon.fake(),88 updateState: sinon.fake(),89 properties: {},90 state: { selectedTask: { status: { value: '' } }, selectedTaskClean: {} }91 })92 assert.equal(testFn.callCount, 1)93 })94 /* eslint-disable-next-line no-undef */95 it('try NOW_INPUT_URL#INVALID_SET and it should be true', () => {96 const testFn = sinon.fake(actions['NOW_INPUT_URL#INVALID_SET'])97 testFn({98 action: { payload: { name: 'test', value: 'test', fieldValue: 'test' } },99 dispatch: sinon.fake(),100 updateState: sinon.fake(),101 properties: {},102 state: { selectedTask: { status: { value: '' } }, selectedTaskClean: {} }103 })104 assert.equal(testFn.callCount, 1)105 })106 /* eslint-disable-next-line no-undef */107 it('try NOW_INPUT_URL#VALUE_SET and it should be true', () => {108 const testFn = sinon.fake(actions['NOW_INPUT_URL#VALUE_SET'])109 testFn({110 action: { payload: { name: 'test', value: 'test' } },111 dispatch: sinon.fake(),112 updateState: sinon.fake(),113 properties: {},114 state: { selectedTask: { status: { value: '' } }, selectedTaskClean: {} }115 })116 assert.equal(testFn.callCount, 1)117 })118 /* eslint-disable-next-line no-undef */119 it('try NOW_TEXTAREA#INPUT and it should be true', () => {120 const testFn = sinon.fake(actions['NOW_TEXTAREA#INPUT'])121 testFn({122 action: { payload: { name: 'test', fieldValue: 'test' } },123 dispatch: sinon.fake(),124 updateState: sinon.fake(),125 properties: {},126 state: { selectedTask: { status: { value: '' } }, selectedTaskClean: {} }127 })128 assert.equal(testFn.callCount, 1)129 })130 /* eslint-disable-next-line no-undef */131 it('try NOW_TYPEAHEAD_MULTI#INVALID_SET and it should be true', () => {132 const testFn = sinon.fake(actions['NOW_TYPEAHEAD_MULTI#INVALID_SET'])133 testFn({134 action: { payload: { name: 'test', value: 'test', fieldValue: 'test' } },135 dispatch: sinon.fake(),136 updateState: sinon.fake(),137 properties: {},138 state: { selectedTask: { status: { value: '' } }, selectedTaskClean: {} }139 })140 assert.equal(testFn.callCount, 1)141 })142 /* eslint-disable-next-line no-undef */143 it('try NOW_TYPEAHEAD_MULTI#SELECTED_ITEMS_SET and it should be true', () => {144 const testFn = sinon.fake(actions['NOW_TYPEAHEAD_MULTI#SELECTED_ITEMS_SET'])145 testFn({146 action: { payload: { name: 'test', value: [], fieldValue: 'test' } },147 dispatch: sinon.fake(),148 updateState: sinon.fake(),149 properties: {},150 state: { selectedTask: { status: { value: '' } }, selectedTaskClean: {} }151 })152 assert.equal(testFn.callCount, 1)153 })154 /* eslint-disable-next-line no-undef */155 it('try NOW_TYPEAHEAD_MULTI#VALUE_SET and it should be true', () => {156 const testFn = sinon.fake(actions['NOW_TYPEAHEAD_MULTI#VALUE_SET'])157 testFn({158 action: { payload: { name: 'test', value: [], fieldValue: 'test' } },159 dispatch: sinon.fake(),160 updateState: sinon.fake(),161 properties: {},162 state: { selectedTask: { status: { value: '' } }, selectedTaskClean: {} }163 })164 assert.equal(testFn.callCount, 1)165 })166 /* eslint-disable-next-line no-undef */167 it('try NOW_MODAL#OPENED_SET and it should be true', () => {168 const testFn = sinon.fake(actions['NOW_MODAL#OPENED_SET'])169 testFn({170 action: { payload: { name: 'test', value: [], fieldValue: 'test' } },171 dispatch: sinon.fake(),172 updateState: sinon.fake(),173 properties: {},174 state: { selectedTask: { status: { value: '' } }, selectedTaskClean: {} }175 })176 assert.equal(testFn.callCount, 1)177 })178 /* eslint-disable-next-line no-undef */179 it('try NOW_RECORD_LIST_CONNECTED#ROW_CLICKED and it should be true', () => {180 const testFn = sinon.fake(actions['NOW_RECORD_LIST_CONNECTED#ROW_CLICKED'])181 testFn({182 action: { payload: { row: { displayValue: 'test', rowData: { value: { get: sinon.fake() } } } } },183 dispatch: sinon.fake(),184 updateState: sinon.fake(),185 properties: {},186 state: { selectedTask: { exception_approvers: { value: '' } }, selectedTaskClean: {} }187 })188 assert.equal(testFn.callCount, 1)189 })190 /* eslint-disable-next-line no-undef */191 it('try NOW_ALERT#ACTION_CLICKED and it should be true', () => {192 const testFn = sinon.fake(actions['NOW_ALERT#ACTION_CLICKED'])193 testFn({194 action: { payload: {} },195 dispatch: sinon.fake(),196 updateState: sinon.fake(),197 properties: {},198 state: { selectedTask: {}, selectedTaskClean: {} }199 })200 assert.equal(testFn.callCount, 1)201 })202})203// helpers.js204/* eslint-disable-next-line no-undef */205describe('discover-task-accordion helpers', () => {206 /* eslint-disable-next-line no-undef */207 it('try isObjectEqual() and it should be true', () => {208 const result = isObjectEqual(209 {210 name: {...

Full Screen

Full Screen

Player.js

Source:Player.js Github

copy

Full Screen

...12}1314test('componentWillUnmount()', t => {15 const wrapper = shallow(<Player />)16 const fake = sinon.fake()17 wrapper.instance().isReady = true18 wrapper.instance().player = { stop: fake }19 wrapper.unmount()20 t.true(fake.calledOnce)21})2223test('getInternalPlayer()', t => {24 const wrapper = shallow(<Player />)25 wrapper.instance().player = { abc: 123 }26 t.true(wrapper.instance().getInternalPlayer('abc') === 123)27})2829test('getInternalPlayer() - null', t => {30 const wrapper = shallow(<Player />)31 wrapper.instance().player = null32 t.true(wrapper.instance().getInternalPlayer() === null)33})3435test('player.load()', t => {36 const wrapper = shallow(<Player url='file.mp4' />)37 const instance = wrapper.instance()38 const fake = sinon.fake()39 instance.handlePlayerMount({ load: fake })40 instance.isLoading = false41 instance.startOnPlay = false42 instance.onDurationCalled = true43 wrapper.setProps({ url: 'another-file.mp4' })44 t.true(fake.calledTwice)45 t.true(fake.calledWith('file.mp4'))46 t.true(fake.calledWith('another-file.mp4'))47 t.true(instance.isLoading)48 t.true(instance.startOnPlay)49 t.false(instance.onDurationCalled)50})5152test('set loadOnReady', t => {53 const stub = sinon.stub(console, 'warn')54 const wrapper = shallow(<Player url='file.mp4' activePlayer={() => null} />)55 const instance = wrapper.instance()56 instance.isLoading = true57 wrapper.setProps({ url: 'another-file.mp4' })58 t.true(stub.calledOnce)59 t.true(instance.loadOnReady === 'another-file.mp4')60 stub.restore()61})6263test('player.play()', t => {64 const wrapper = shallow(<Player />)65 const load = sinon.fake()66 const play = sinon.fake()67 wrapper.instance().handlePlayerMount({ load, play })68 wrapper.setProps({ playing: true })69 t.true(play.calledOnce)70})7172test('player.pause()', t => {73 const wrapper = shallow(<Player playing />)74 const load = sinon.fake()75 const pause = sinon.fake()76 wrapper.instance().handlePlayerMount({ load, pause })77 wrapper.instance().isPlaying = true78 wrapper.setProps({ playing: false })79 t.true(pause.calledOnce)80})8182test('player.setVolume()', t => {83 const wrapper = shallow(<Player volume={0.5} />)84 const load = sinon.fake()85 const setVolume = sinon.fake()86 wrapper.instance().handlePlayerMount({ load, setVolume })87 wrapper.setProps({ volume: 0.4 })88 t.true(setVolume.calledOnce)89})9091test('player.mute()', t => {92 const wrapper = shallow(<Player muted={false} />)93 const load = sinon.fake()94 const mute = sinon.fake()95 wrapper.instance().handlePlayerMount({ load, mute })96 wrapper.setProps({ muted: true })97 t.true(mute.calledOnce)98})99100test('player.unmute()', t => {101 const wrapper = shallow(<Player muted volume={0.8} />)102 const load = sinon.fake()103 const unmute = sinon.fake()104 const setVolume = sinon.fake()105 wrapper.instance().handlePlayerMount({ load, unmute, setVolume })106 wrapper.setProps({ muted: false })107 t.true(unmute.calledOnce)108 return new Promise(resolve => setTimeout(() => {109 t.true(setVolume.calledOnceWith(0.8))110 resolve()111 }))112})113114test('player.setPlaybackRate()', t => {115 const wrapper = shallow(<Player playbackRate={1} />)116 const load = sinon.fake()117 const setPlaybackRate = sinon.fake()118 wrapper.instance().handlePlayerMount({ load, setPlaybackRate })119 wrapper.setProps({ playbackRate: 0.5 })120 t.true(setPlaybackRate.calledOnce)121})122123const COMMON_METHODS = ['getDuration', 'getCurrentTime', 'getSecondsLoaded']124125for (const method of COMMON_METHODS) {126 test(`${method}()`, t => {127 const instance = shallow(<Player />).instance()128 instance.player = { [method]: () => 123 }129 instance.isReady = true130 t.true(instance[method]() === 123)131 })132133 test(`${method}() - null`, t => {134 const instance = shallow(<Player />).instance()135 t.true(instance[method]() === null)136 })137}138139test('progress()', t => {140 const load = sinon.fake()141 const onProgress = sinon.fake()142 const instance = shallow(<Player url='file.mp4' onProgress={onProgress} />).instance()143 instance.handlePlayerMount({144 load,145 getCurrentTime: sinon.fake.returns(10),146 getSecondsLoaded: sinon.fake.returns(20),147 getDuration: sinon.fake.returns(40)148 })149 instance.isReady = true150 instance.progress()151 instance.progress() // Call twice to ensure onProgress is not called again152 t.true(onProgress.calledOnceWith({153 loaded: 0.5,154 loadedSeconds: 20,155 played: 0.25,156 playedSeconds: 10157 }))158})159160test('seekTo() - seconds', t => {161 const load = sinon.fake()162 const seekTo = sinon.fake()163 const instance = shallow(<Player />).instance()164 instance.handlePlayerMount({ load, seekTo })165 instance.isReady = true166 instance.seekTo(10)167 t.true(seekTo.calledOnceWith(10))168})169170test('seekTo() - fraction', t => {171 const load = sinon.fake()172 const seekTo = sinon.fake()173 const instance = shallow(<Player />).instance()174 instance.handlePlayerMount({175 load,176 seekTo,177 getDuration: sinon.fake.returns(10)178 })179 instance.isReady = true180 instance.seekTo(0.5)181 t.true(seekTo.calledOnceWith(5))182})183184test('seekTo() - warning', t => {185 const stub = sinon.stub(console, 'warn')186 const load = sinon.fake()187 const seekTo = sinon.fake()188 const instance = shallow(<Player />).instance()189 instance.handlePlayerMount({190 load,191 seekTo,192 getDuration: sinon.fake.returns(null)193 })194 instance.isReady = true195 instance.seekTo(0.5)196 t.true(seekTo.notCalled)197 t.true(stub.calledOnce)198 stub.restore()199})200201test('seekTo() - set seekOnPlay', t => {202 const load = sinon.fake()203 const seekTo = sinon.fake()204 const instance = shallow(<Player />).instance()205 instance.handlePlayerMount({ load, seekTo })206 instance.isReady = false207 instance.seekTo(10)208 t.true(seekTo.notCalled)209 t.true(instance.seekOnPlay === 10)210})211212test('onReady()', t => {213 const onReady = sinon.fake()214 const load = sinon.fake()215 const setVolume = sinon.fake()216 const play = sinon.fake()217 const instance = shallow(<Player onReady={onReady} playing volume={1} />).instance()218 instance.handlePlayerMount({ load, setVolume, play })219 instance.handleDurationCheck = sinon.fake()220 instance.isReady = true221 instance.handleReady()222 t.true(setVolume.calledOnceWith(1))223 t.true(play.calledOnce)224})225226test('loadOnReady', t => {227 const load = sinon.fake()228 const play = sinon.fake()229 const instance = shallow(<Player />).instance()230 instance.handlePlayerMount({ load, play })231 instance.handleDurationCheck = sinon.fake()232 instance.loadOnReady = 'file.mp4'233 instance.handleReady()234 t.true(load.calledWith('file.mp4'))235 t.true(play.notCalled)236})237238test('onPlay()', t => {239 const onPlay = sinon.fake()240 const instance = shallow(<Player onPlay={onPlay} />).instance()241 instance.handleDurationCheck = sinon.fake()242 instance.handlePlay()243 t.true(onPlay.calledOnce)244 t.true(instance.isPlaying)245 t.false(instance.isLoading)246})247248test('onStart()', t => {249 const onStart = sinon.fake()250 const instance = shallow(<Player onStart={onStart} />).instance()251 instance.handleDurationCheck = sinon.fake()252 instance.startOnPlay = true253 instance.handlePlay()254 t.true(onStart.calledOnce)255 t.false(instance.startOnPlay)256})257258test('seekOnPlay', t => {259 const seekTo = sinon.stub(Player.prototype, 'seekTo')260 const instance = shallow(<Player />).instance()261 instance.handleDurationCheck = sinon.fake()262 instance.seekOnPlay = 10263 instance.handlePlay()264 t.true(seekTo.calledOnceWith(10))265 t.true(instance.seekOnPlay === null)266 seekTo.restore()267})268269test('onPause()', t => {270 const onPause = sinon.fake()271 const instance = shallow(<Player onPause={onPause} />).instance()272 instance.isLoading = false273 instance.handlePause()274 t.true(onPause.calledOnce)275 t.false(instance.isPlaying)276})277278test('onPause() - isLoading', t => {279 const onPause = sinon.fake()280 const instance = shallow(<Player onPause={onPause} />).instance()281 instance.isLoading = true282 instance.handlePause()283 t.true(onPause.notCalled)284})285286test('onEnded()', t => {287 const activePlayer = () => null288 const onEnded = sinon.fake()289 const instance = shallow(<Player activePlayer={activePlayer} onEnded={onEnded} />).instance()290 instance.isPlaying = true291 instance.handleEnded()292 t.true(onEnded.calledOnce)293 t.false(instance.isPlaying)294})295296test('loopOnEnded', t => {297 const activePlayer = () => null298 activePlayer.loopOnEnded = true299 const seekTo = sinon.stub(Player.prototype, 'seekTo')300 const instance = shallow(<Player loop activePlayer={activePlayer} />).instance()301 instance.isPlaying = true302 instance.handleEnded()303 t.true(seekTo.calledOnceWith(0))304 t.true(instance.isPlaying)305 seekTo.restore()306})307308test('handleDurationCheck', t => {309 const onDuration = sinon.fake()310 const instance = shallow(<Player onDuration={onDuration} />).instance()311 instance.getDuration = sinon.fake.returns(10)312 instance.handleDurationCheck()313 instance.handleDurationCheck() // Call twice to ensure onDuration is not called again314 t.true(onDuration.calledOnceWith(10))315 t.true(instance.onDurationCalled)316})317318test('durationCheckTimeout', t => {319 const onDuration = sinon.fake()320 const instance = shallow(<Player onDuration={onDuration} />).instance()321 instance.getDuration = sinon.fake.returns(null)322 instance.durationCheckTimeout = null323 instance.handleDurationCheck()324 t.true(onDuration.notCalled)325 t.truthy(instance.durationCheckTimeout) ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var fake = sinon.fake();3fake();4fake();5console.log(fake.callCount);6console.log(fake.called);7console.log(fake.calledOnce);8console.log(fake.calledTwice);9console.log(fake.calledThrice);10{11 "scripts": {12 },13 "dependencies": {14 }15}16Sinon.js - sinon.fake.returns()17Sinon.js - sinon.fake.throws()18Sinon.js - sinon.fake.resolves()19Sinon.js - sinon.fake.yields()20Sinon.js - sinon.fake.yieldsTo()21Sinon.js - sinon.fake.yieldsAsync()22Sinon.js - sinon.fake.resolvesAsync()23Sinon.js - sinon.fake.returnsAsync()24Sinon.js - sinon.fake.throwsAsync()25Sinon.js - sinon.fake.withArgs()26Sinon.js - sinon.fakeServer.create()27Sinon.js - sinon.fakeServer.xhr.restore(

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const assert = require('assert');3const myFunc = require('./myFunc');4describe('myFunc', function() {5 it('should call the callback', function() {6 const callback = sinon.fake();7 myFunc(callback);8 assert(callback.called);9 });10});11const myFunc = function(callback) {12 callback();13};14module.exports = myFunc;15const sinon = require('sinon');16const assert = require('assert');17const myFunc = require('./myFunc');18describe('myFunc', function() {19 it('should call the callback', function() {20 const callback = sinon.spy();21 myFunc(callback);22 assert(callback.called);23 });24});25const myFunc = function(callback) {26 callback();27};28module.exports = myFunc;29const sinon = require('sinon');30const assert = require('assert');31const myFunc = require('./myFunc');32describe('myFunc', function() {33 it('should call the callback', function() {34 const callback = sinon.stub().returns('foo');35 myFunc(callback);36 assert(callback.called);37 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myObj = {4 myMethod: function() {5 return 'hello';6 }7};8var spy = sinon.spy(myObj, 'myMethod');9myObj.myMethod();10var sinon = require('sinon');11var assert = require('assert');12var myObj = {13 myMethod: function() {14 return 'hello';15 }16};17var stub = sinon.stub(myObj, 'myMethod').callsFake(function() {18 return 'hello world';19});20var result = myObj.myMethod();21var sinon = require('sinon');22var assert = require('assert');23var myObj = {24 myMethod: function() {25 return 'hello';26 }27};28var stub = sinon.stub(myObj, 'myMethod').callsFake(function() {29 return 'hello world';30});31var result = myObj.myMethod();32var sinon = require('sinon');33var assert = require('assert');34var myObj = {35 myMethod: function() {36 return 'hello';37 }38};39var stub = sinon.stub(myObj, 'myMethod').callsFake(function() {40 return 'hello world';41});42var result = myObj.myMethod();43var sinon = require('sinon');44var assert = require('assert');45var myObj = {46 myMethod: function() {47 return 'hello';48 }49};50var stub = sinon.stub(myObj, 'myMethod').callsFake(function() {51 return 'hello world';52});53var result = myObj.myMethod();54var sinon = require('sinon');55var assert = require('assert');56var myObj = {57 myMethod: function() {58 return 'hello';59 }60};61var stub = sinon.stub(myObj, 'my

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var sinon = require('sinon');3var myObj = {4 myMethod: function() {5 return 1;6 }7};8var fake = sinon.fake.returns(2);9var myObj = {10};11assert.equal(myObj.myMethod(), 2);12var assert = require('assert');13var sinon = require('sinon');14var myObj = {15 myMethod: function() {16 return 1;17 }18};19var fake = sinon.fake.returns(2);20var myObj = {21};22assert.equal(myObj.myMethod(), 2);23var assert = require('assert');24var sinon = require('sinon');25var myObj = {26 myMethod: function() {27 return 1;28 }29};30var fake = sinon.fake.returns(2);31var myObj = {32};33assert.equal(myObj.myMethod(), 2);34var assert = require('assert');35var sinon = require('sinon');36var myObj = {37 myMethod: function() {38 return 1;39 }40};41var fake = sinon.fake.returns(2);42var myObj = {43};44assert.equal(myObj.myMethod(), 2);45var assert = require('assert');46var sinon = require('sinon');47var myObj = {48 myMethod: function() {49 return 1;50 }51};52var fake = sinon.fake.returns(2);53var myObj = {54};55assert.equal(myObj.myMethod(), 2);56var assert = require('assert');57var sinon = require('sinon');58var myObj = {59 myMethod: function() {60 return 1;61 }62};63var fake = sinon.fake.returns(2);64var myObj = {65};66assert.equal(myObj.myMethod(), 2);

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const assert = require('assert');3const myModule = require('./myModule');4const myModule2 = require('./myModule2');5const fakeFunction = sinon.fake();6myModule(fakeFunction);7assert(fakeFunction.called);8assert(fakeFunction.calledOnce);9assert(fakeFunction.calledWith('foo', 'bar'));10assert(fakeFunction.calledWithMatch('foo'));11assert(fakeFunction.calledWithMatch('foo', 'bar'));12assert(fakeFunction.calledWithMatch('foo', 'bar', 'baz'));13assert(fakeFunction.calledWithMatch('foo', 'bar', 'baz', 'qux'));14assert(fakeFunction.calledWithMatch('foo', 'bar', 'baz', 'qux', 'quux'));15assert(fakeFunction.calledWithMatch('foo', 'bar', 'baz', 'qux', 'quux', 'corge'));16assert(fakeFunction.calledWithMatch('foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault'));17assert(fakeFunction.calledWithMatch('foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply'));18assert(fakeFunction.calledWithMatch('foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply', 'waldo'));19assert(fakeFunction.calledWithMatch('foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply', 'waldo', 'fred'));20assert(fakeFunction.calledWithMatch('foo', 'bar', 'baz',

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var sinon = require('sinon');3function getWeather(city, callback) {4 callback(error, body);5 });6}7var fake = sinon.fake.yields(null, 'fake body');8var stub = sinon.stub(request, 'request').callsFake(fake);9getWeather('new york', function(error, body) {10 console.log(body);11});12stub.restore();13Related Posts: How to use the sinon.spy() method of sinon.js to test a function that calls the request() method of the request module in the node.js environment14How to use the sinon.stub() method of sinon.js to test a function that calls the request() method of the request module in the node.js environment15How to use the sinon.fake() method of sinon.js to test a function that calls the request() method of the request module in the node.js environment16How to use the sinon.fake() method of sinon.js to test a function that calls the createClient() method of the redis module in the node.js environment17How to use the sinon.stub() method of sinon.js to test a function that calls the createClient() method of the redis module in the node.js environment18How to use the sinon.spy() method of sinon.js to test a function that calls the createClient() method of the redis module in the node.js environment19How to use the sinon.fake() method of sinon.js to test a function that calls the createClient() method of the redis module in the node.js environment20How to use the sinon.stub() method of sinon.js to test a function that calls the createClient() method of the redis module in the node.js environment21How to use the sinon.spy() method of sinon.js to test a function that calls the createClient() method of the redis module in the node.js environment22How to use the sinon.fake() method

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 sinon 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