How to use findPlugin method in Jest

Best JavaScript code snippet using jest

dyn2.js

Source:dyn2.js Github

copy

Full Screen

...6    document.enablePackage(libsbml.DynExtension.prototype.getXmlnsL3V1V1(), 'dyn', true)7    document.enablePackage(libsbml.CompExtension.prototype.getXmlnsL3V1V1(), 'comp', true)8    document.setPackageRequired("dyn", true)9    document.setPackageRequired("comp", true)10    const distdoc = libsbml.castObject(document.findPlugin("dyn"), libsbml.DistribSBMLDocumentPlugin)11    const model = document.createModel()12    model.setId('singleCell')13    const parser = new libsbml.SBMLFormulaParser()14    // create the Compartment15    let compartment = model.createCompartment()16    compartment.setId("Loc1")17    compartment.setConstant(false)18    compartment.setSize(1)19    compartment.setSpatialDimensions(2.0)20    let cplugin = libsbml.castObject(compartment.findPlugin("dyn"), libsbml.DynCompartmentPlugin)21    let component = cplugin.createSpatialComponent()22    component.setSpatialIndex(libsbml.DYN_SPATIALKIND_CARTESIANX)23    component.setVariable("q1_X")24    component = cplugin.createSpatialComponent()25    component.setSpatialIndex(libsbml.DYN_SPATIALKIND_CARTESIANY)26    component.setVariable("q1_Y")27    let compPlugin = libsbml.castObject(compartment.findPlugin("comp"), libsbml.CompSBasePlugin)28    let relement = compPlugin.createReplacedElement()29    relement.setIdRef("C")30    relement.setSubmodelRef("GRID_1_1_cell")31    compartment = model.createCompartment()32    compartment.setId("Loc2")33    compartment.setConstant(false)34    compartment.setSize(1)35    compartment.setSpatialDimensions(2.0)36    cplugin = libsbml.castObject(compartment.findPlugin("dyn"), libsbml.DynCompartmentPlugin)37    component = cplugin.createSpatialComponent()38    component.setSpatialIndex(libsbml.DYN_SPATIALKIND_CARTESIANX)39    component.setVariable("q2_X")40    component = cplugin.createSpatialComponent()41    component.setSpatialIndex(libsbml.DYN_SPATIALKIND_CARTESIANY)42    component.setVariable("q2_Y")43    compPlugin = libsbml.castObject(compartment.findPlugin("comp"), libsbml.CompSBasePlugin)44    relement = compPlugin.createReplacedElement()45    relement.setIdRef("C")46    relement.setSubmodelRef("GRID_1_2_cell")47    compartment = model.createCompartment()48    compartment.setId("Loc3")49    compartment.setConstant(false)50    compartment.setSize(1)51    compartment.setSpatialDimensions(2.0)52    cplugin = libsbml.castObject(compartment.findPlugin("dyn"), libsbml.DynCompartmentPlugin)53    component = cplugin.createSpatialComponent()54    component.setSpatialIndex(libsbml.DYN_SPATIALKIND_CARTESIANX)55    component.setVariable("q3_X")56    component = cplugin.createSpatialComponent()57    component.setSpatialIndex(libsbml.DYN_SPATIALKIND_CARTESIANY)58    component.setVariable("q3_Y")59    compPlugin = libsbml.castObject(compartment.findPlugin("comp"), libsbml.CompSBasePlugin)60    relement = compPlugin.createReplacedElement()61    relement.setIdRef("C")62    relement.setSubmodelRef("GRID_2_1_cell")63    compartment = model.createCompartment()64    compartment.setId("Loc4")65    compartment.setConstant(false)66    compartment.setSize(1)67    compartment.setSpatialDimensions(2.0)68    cplugin = libsbml.castObject(compartment.findPlugin("dyn"), libsbml.DynCompartmentPlugin)69    component = cplugin.createSpatialComponent()70    component.setSpatialIndex(libsbml.DYN_SPATIALKIND_CARTESIANX)71    component.setVariable("q4_X")72    component = cplugin.createSpatialComponent()73    component.setSpatialIndex(libsbml.DYN_SPATIALKIND_CARTESIANY)74    component.setVariable("q4_Y")75    compPlugin = libsbml.castObject(compartment.findPlugin("comp"), libsbml.CompSBasePlugin)76    relement = compPlugin.createReplacedElement()77    relement.setIdRef("C")78    relement.setSubmodelRef("GRID_2_2_cell")79    // create Parameters80    let param = model.createParameter()81    param.initDefaults()82    param.setId("q1_X")83    param.setValue(1)84    param = model.createParameter()85    param.initDefaults()86    param.setId("q1_Y")87    param.setValue(1)88    param = model.createParameter()89    param.initDefaults()90    param.setId("q2_X")91    param.setValue(2)92    param = model.createParameter()93    param.initDefaults()94    param.setId("q2_Y")95    param.setValue(1)96    param = model.createParameter()97    param.initDefaults()98    param.setId("q3_X")99    param.setValue(1)100    param = model.createParameter()101    param.initDefaults()102    param.setId("q3_Y")103    param.setValue(2)104    param = model.createParameter()105    param.initDefaults()106    param.setId("q4_X")107    param.setValue(2)108    param = model.createParameter()109    param.initDefaults()110    param.setId("q4_Y")111    param.setValue(2)112    // create SubModels113    const mplugin = libsbml.castObject(model.findPlugin("comp"), libsbml.CompModelPlugin)114    let submodel = mplugin.createSubmodel()115    submodel.setId("GRID_1_1_cell")116    submodel.setModelRef("Cell")117    submodel = mplugin.createSubmodel()118    submodel.setId("GRID_1_2_cell")119    submodel.setModelRef("Cell")120    submodel = mplugin.createSubmodel()121    submodel.setId("GRID_2_1_cell")122    submodel.setModelRef("Cell")123    submodel = mplugin.createSubmodel()124    submodel.setId("GRID_2_2_cell")125    submodel.setModelRef("Cell")126    // create the ModelDefinition127    const dplugin = libsbml.castObject(document.findPlugin("comp"), libsbml.CompSBMLDocumentPlugin)128    const mdef = dplugin.createModelDefinition()129    mdef.setId("Cell")130    compartment = mdef.createCompartment()131    compartment.initDefaults()132    compartment.setId("C")133    compartment.setSpatialDimensions(2.0)134    compartment.setSize(1.0)135    let species = mdef.createSpecies()136    species.setId("R")137    species.setCompartment("C")138    species.setHasOnlySubstanceUnits(false)139    species.setBoundaryCondition(false)140    species.setConstant(false)141    species = mdef.createSpecies()142    species.setId("S")143    species.setCompartment("C")144    species.setHasOnlySubstanceUnits(false)145    species.setBoundaryCondition(false)146    species.setConstant(false)147    let reaction = mdef.createReaction()148    reaction.setId("Degradation_R")149    reaction.setReversible(false)150    reaction.setCompartment("C")151    let reactant = reaction.createReactant();152    reactant.setSpecies("R")153    reactant.setStoichiometry(1)154    reactant.setConstant(true)155    reaction = mdef.createReaction()156    reaction.setId("Degradation_S")157    reaction.setReversible(false)158    reaction.setCompartment("C")159    reactant = reaction.createReactant()160    reactant.setSpecies("S")161    reactant.setStoichiometry(1)162    reactant.setConstant(true)163    document.checkConsistency()164    const event = mdef.createEvent()165    event.setId("event0")166    event.setUseValuesFromTriggerTime(false)167    const eplugin = libsbml.castObject(event.findPlugin("dyn"), libsbml.DynEventPlugin)168    eplugin.setApplyToAll(true)169    eplugin.setCboTerm("http://cbo.biocomplexity.indiana.edu/svn/cbo/trunk/CBO_1_0.owl#CellDivision")170    const trigger = event.createTrigger()171    trigger.setInitialValue(false)172    trigger.setPersistent(false)173    trigger.setMath(parser.parseL3Formula("true"))174    const writer = new libsbml.SBMLWriter()175    const serializedSBML = writer.writeSBMLToString(document)176    console.log(serializedSBML)177    libsbml.destroy(document)178  } catch(error) {179    console.log(error.stack)180  }181})

Full Screen

Full Screen

findPluginSpec.js

Source:findPluginSpec.js Github

copy

Full Screen

...19    loadPlugin.reset();20  });21  it('grunt-contrib-foo', () => {22    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-foo/tasks')).returns(true);23    jit.findPlugin('foo');24    assert.deepEqual(25      loadPlugin.getCall(0).args,26      ['grunt-contrib-foo', path.resolve('node_modules/grunt-contrib-foo/tasks')]);27  });28  it('grunt-foo', () => {29    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-foo/tasks')).returns(false);30    existsSync.withArgs(path.resolve('node_modules/grunt-foo/tasks')).returns(true);31    jit.findPlugin('foo');32    assert.deepEqual(33      loadPlugin.getCall(0).args,34      ['grunt-foo', path.resolve('node_modules/grunt-foo/tasks')]);35  });36  it('foo', () => {37    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-foo/tasks')).returns(false);38    existsSync.withArgs(path.resolve('node_modules/grunt-foo/tasks')).returns(false);39    existsSync.withArgs(path.resolve('node_modules/foo/tasks')).returns(true);40    jit.findPlugin('foo');41    assert.deepEqual(42      loadPlugin.getCall(0).args,43      ['foo', path.resolve('node_modules/foo/tasks')]);44  });45  it('CamelCase', () => {46    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-foo-bar/tasks')).returns(false);47    existsSync.withArgs(path.resolve('node_modules/grunt-foo-bar/tasks')).returns(true);48    jit.findPlugin('fooBar');49    assert.deepEqual(50      loadPlugin.getCall(0).args,51      ['grunt-foo-bar', path.resolve('node_modules/grunt-foo-bar/tasks')]);52  });53  it('snake_case', () => {54    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-foo-bar/tasks')).returns(false);55    existsSync.withArgs(path.resolve('node_modules/grunt-foo-bar/tasks')).returns(false);56    existsSync.withArgs(path.resolve('node_modules/foo-bar/tasks')).returns(true);57    jit.findPlugin('foo_bar');58    assert.deepEqual(59      loadPlugin.getCall(0).args,60      ['foo-bar', path.resolve('node_modules/foo-bar/tasks')]);61  });62  it('Custom task', () => {63    jit.customTasksDir = path.resolve('custom');64    existsSync.withArgs(path.resolve('custom/foo.js')).returns(true);65    jit.findPlugin('foo');66    assert.deepEqual(67      loadPlugin.getCall(0).args,68      ['foo', path.resolve('custom/foo.js'), true]);69  });70  it('Custom task: CoffeeScript', () => {71    jit.customTasksDir = path.resolve('custom');72    existsSync.withArgs(path.resolve('custom/foo.js')).returns(false);73    existsSync.withArgs(path.resolve('custom/foo.coffee')).returns(true);74    jit.findPlugin('foo');75    assert.deepEqual(76      loadPlugin.getCall(0).args,77      ['foo', path.resolve('custom/foo.coffee'), true]);78  });79  it('findUp', () => {80    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-foo/tasks')).returns(false);81    existsSync.withArgs(path.resolve('node_modules/grunt-foo/tasks')).returns(false);82    existsSync.withArgs(path.resolve('node_modules/foo/tasks')).returns(false);83    existsSync.withArgs(path.resolve('../node_modules/grunt-contrib-foo/tasks')).returns(true);84    jit.findPlugin('foo');85    assert.deepEqual(86      loadPlugin.getCall(0).args,87      ['grunt-contrib-foo', path.resolve('../node_modules/grunt-contrib-foo/tasks')]);88  });89  it('not Found', () => {90    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-foo/tasks')).returns(false);91    existsSync.withArgs(path.resolve('node_modules/grunt-foo/tasks')).returns(false);92    existsSync.withArgs(path.resolve('node_modules/foo/tasks')).returns(false);93    existsSync.withArgs(path.resolve('../node_modules/grunt-contrib-foo/tasks')).returns(false);94    jit.findPlugin('foo');95    assert(loadPlugin.callCount === 0);96  });97  it('Static mapping', () => {98    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-bar/tasks')).returns(false);99    existsSync.withArgs(path.resolve('node_modules/grunt-foo/tasks')).returns(true);100    jit.findPlugin('bar');101    assert.deepEqual(102      loadPlugin.getCall(0).args,103      ['grunt-foo', path.resolve('node_modules/grunt-foo/tasks')]);104  });105  it('Static mapping for private module', () => {106    jit.mappings = {107      foo: '@abc/grunt-foo'108    };109    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-foo/tasks')).returns(false);110    existsSync.withArgs(path.resolve('node_modules/grunt-foo/tasks')).returns(false);111    existsSync.withArgs(path.resolve('node_modules/foo/tasks')).returns(false);112    existsSync.withArgs(path.resolve('node_modules/@abc/grunt-foo/tasks')).returns(true);113    jit.findPlugin('foo');114    assert.deepEqual(115      loadPlugin.getCall(0).args,116      ['@abc/grunt-foo', path.resolve('node_modules/@abc/grunt-foo/tasks')]);117  });118  it('Static mapping for custom task', () => {119    jit.mappings = {120      foo: 'custom/foo.js'121    };122    existsSync.withArgs(path.resolve('node_modules/grunt-contrib-foo/tasks')).returns(false);123    existsSync.withArgs(path.resolve('node_modules/grunt-foo/tasks')).returns(false);124    existsSync.withArgs(path.resolve('node_modules/foo/tasks')).returns(false);125    existsSync.withArgs(path.resolve('custom/foo.js')).returns(true);126    jit.findPlugin('foo');127    assert.deepEqual(128      loadPlugin.getCall(0).args,129      ['foo', path.resolve('custom/foo.js'), true]);130  });131  it('Other node_modules dir', () => {132    jit.pluginsRoot = 'other/dir';133    existsSync.withArgs(path.resolve('other/dir/grunt-contrib-foo/tasks')).returns(false);134    existsSync.withArgs(path.resolve('other/dir/grunt-foo/tasks')).returns(false);135    existsSync.withArgs(path.resolve('other/dir/foo/tasks')).returns(true);136    jit.findPlugin('foo');137    assert.deepEqual(138      loadPlugin.getCall(0).args,139      ['foo', path.resolve('other/dir/foo/tasks')]);140  });...

Full Screen

Full Screen

createKarmaConfig-test.js

Source:createKarmaConfig-test.js Github

copy

Full Screen

...13    let plugin = {'framework:test': []}14    expect(processPluginConfig([plugin])).toEqual([['test'], [plugin]])15  })16})17describe('findPlugin()', () => {18  let plugins = ['foo', plugin, 'bar']19  it('finds a plugin by type:name identifier', () => {20    expect(findPlugin(plugins, 'framework:test')).toBe(plugin)21  })22  it('returns null if no matching identifier is found', () => {23    expect(findPlugin(plugins, 'framework:best')).toBe(null)24  })25})26describe('getKarmaPluginConfig()', function() {27  this.timeout(10000)28  describe('without user config', () => {29    let expectedDefaultPlugins = [30      'launcher:Chrome',31      'preprocessor:sourcemap',32      'preprocessor:webpack',33      'framework:mocha',34      'reporter:mocha',35    ]36    it('defaults to Mocha and ChromeHeadless', () => {37      let {browsers, frameworks, reporters, plugins} = getKarmaPluginConfig()38      expect(browsers).toEqual(['ChromeHeadless'])39      expect(frameworks).toEqual(['mocha', 'webpack'])40      expect(reporters).toEqual(['mocha'])41      expectedDefaultPlugins.forEach(plugin =>42        expect(findPlugin(plugins, plugin)).toExist()43      )44    })45    it('adds coverage config when asked to', () => {46      let {browsers, frameworks, reporters, plugins} = getKarmaPluginConfig({codeCoverage: true})47      expect(browsers).toEqual(['ChromeHeadless'])48      expect(frameworks).toEqual(['mocha', 'webpack'])49      expect(reporters).toEqual(['mocha', 'coverage'])50      expectedDefaultPlugins.concat(['preprocessor:coverage']).forEach(plugin => {51        expect(findPlugin(plugins, plugin)).toExist()52      })53    })54  })55  describe('with user config', () => {56    let tapeFramework = {'framework:tape': []}57    let tapReporter = {'reporter:tap': []}58    it('defaults the reporter to dots if only a framework plugin is configured', () => {59      let {frameworks, reporters, plugins} = getKarmaPluginConfig({60        userConfig: {61          frameworks: [tapeFramework],62        },63      })64      expect(frameworks).toEqual(['tape', 'webpack'])65      expect(reporters).toEqual(['dots'])66      expect(findPlugin(plugins, 'framework:tape')).toExist()67    })68    it('defaults the reporter to dots if only a framework name and plugin is configured', () => {69      let {frameworks, reporters, plugins} = getKarmaPluginConfig({70        userConfig: {71          frameworks: ['tape'],72          plugins: [tapeFramework],73        },74      })75      expect(frameworks).toEqual(['tape', 'webpack'])76      expect(reporters).toEqual(['dots'])77      expect(findPlugin(plugins, 'framework:tape')).toExist()78    })79    it('uses the given reporter if a plugin is also configured', () => {80      let {frameworks, reporters, plugins} = getKarmaPluginConfig({81        userConfig: {82          frameworks: [tapeFramework],83          reporters: [tapReporter],84        },85      })86      expect(frameworks).toEqual(['tape', 'webpack'])87      expect(reporters).toEqual(['tap'])88      expect(findPlugin(plugins, 'framework:tape')).toExist()89      expect(findPlugin(plugins, 'reporter:tap')).toExist()90    })91    it('uses the given reporter if a name plugin is also configured', () => {92      let {frameworks, reporters, plugins} = getKarmaPluginConfig({93        userConfig: {94          frameworks: ['tape'],95          reporters: ['tap'],96          plugins: [tapeFramework, tapReporter],97        },98      })99      expect(frameworks).toEqual(['tape', 'webpack'])100      expect(reporters).toEqual(['tap'])101      expect(findPlugin(plugins, 'framework:tape')).toExist()102      expect(findPlugin(plugins, 'reporter:tap')).toExist()103    })104    it('makes sure the Mocha plugins will be loaded when necessary', () => {105      let {frameworks, reporters, plugins} = getKarmaPluginConfig({106        userConfig: {107          frameworks: ['mocha', 'chai', 'chai-as-promised'],108          reporters: ['mocha'],109          plugins: [{'framework: chai': []}],110        },111      })112      expect(frameworks).toEqual(['mocha', 'chai', 'chai-as-promised', 'webpack'])113      expect(reporters).toEqual(['mocha'])114      expect(findPlugin(plugins, 'framework:mocha')).toExist()115      expect(findPlugin(plugins, 'reporter:mocha')).toExist()116      expect(findPlugin(plugins, 'framework: chai')).toExist()117    })118    it('makes sure the Chrome launcher plugin will be loaded when necessary', () => {119      let {browsers, plugins} = getKarmaPluginConfig({120        userConfig: {121          browsers: ['Chrome']122        },123      })124      expect(browsers).toEqual(['Chrome'])125      expect(findPlugin(plugins, 'launcher:Chrome')).toExist()126    })127  })128})129describe('createKarmaConfig()', () => {130  it('includes default test files pattern', () => {131    let config = createKarmaConfig({}, {}, {}, {})132    expect(config.files).toEqual([133      '+(src|test?(s))/**/*+(.spec|.test).js',134    ])135  })136  it('includes default mocha reporter config', () => {137    let config = createKarmaConfig({}, {}, {}, {})138    expect(config.mochaReporter).toEqual({showDiff: true})139  })...

Full Screen

Full Screen

index.spec.js

Source:index.spec.js Github

copy

Full Screen

1const mockExists = jest.fn();2jest.mock('./module-exists', () => mockExists);3const configPreset = require('./index');4const defaultSettings = require('./default-settings');5function findPlugin(pluginList, expectedPlugin) {6  return pluginList.find(plugin =>7    Array.isArray(plugin)8      ? plugin[0] === expectedPlugin9      : plugin === expectedPlugin10  );11}12it('can exclude react preset', () => {13  let { presets } = configPreset();14  expect(presets[1]).toBe(require('@babel/preset-react'));15  ({ presets } = configPreset(null, { react: false }));16  expect(presets[1]).toBeUndefined();17});18describe('babel-plugin-extract-format-message', () => {19  const plugin = require('babel-plugin-extract-format-message');20  it('can be excluded', () => {21    let { plugins } = configPreset();22    expect(findPlugin(plugins, plugin)).not.toBeFalsy();23    ({ plugins } = configPreset(null, { extractFormatMessage: false }));24    expect(findPlugin(plugins)).toBeFalsy();25  });26  it('consumes the default options', () => {27    const { plugins } = configPreset();28    const settings = findPlugin(plugins, plugin)[1]29    expect(settings).toMatchObject(defaultSettings.extractFormatMessage);30  });31});32describe('babel-plugin-transform-format-message', () => {33  const plugin = require('babel-plugin-transform-format-message');34  it('can be excluded', () => {35    let { plugins } = configPreset();36    expect(findPlugin(plugins, plugin)).not.toBeFalsy();37    ({ plugins } = configPreset(null, { transformFormatMessage: false }));38    expect(findPlugin(plugins, plugin)).toBeFalsy();39  });40  it('consume the default options', () => {41    const { plugins } = configPreset();42    const settings = findPlugin(plugins, plugin)[1]43    expect(settings).toMatchObject(defaultSettings.transformFormatMessage);44  });45});46describe('babel-plugin-styled-components', () => {47  const plugin = require('babel-plugin-styled-components');48  it('is excluded if project is not using styled-components', () => {49    const { plugins } = configPreset();50    expect(findPlugin(plugins, plugin)).toBeFalsy();51  });52  it('is inlcuded if styled-components is present', () => {53    mockExists.mockReturnValueOnce(true);54    const { plugins } = configPreset();55    expect(findPlugin(plugins, plugin)[0]).toBe(plugin);56  });...

Full Screen

Full Screen

getResource.js

Source:getResource.js Github

copy

Full Screen

1import { resources } from '../../lib/conf'2import { getResource } from '../getResource'3import { findPlugin } from '../findPlugin'4jest.mock('../findPlugin')5beforeEach(() => {6  Object.keys(resources).forEach(key => delete resources[key])7})8test('If exists the resource returns the resource', () => {9  resources.test = Math.random()10  expect(getResource('test')).toEqual(resources.test)11})12test('If exists the resource, does not call findPlugin', () => {13  resources.test = Math.random()14  getResource('test')15  expect(findPlugin).not.toHaveBeenCalled()16})17test('If not exists the resource, call findPlugin (plugin no exists, so throw)', () => {18  expect(() => getResource('test')).toThrow()19  expect(findPlugin).toHaveBeenCalled()20})21test('If the resource not exists, creates one', () => {22  findPlugin.mockReturnValue({ name: 'voidplugin', conf: {} })23  expect(getResource('test')).toEqual({24    url: 'test',25    plugin: {26      name: 'voidplugin',27      conf: {}28    },29    value: undefined,30    callbacks: {}31  })32})33test('sets the resource in resources under url', () => {34  findPlugin.mockReturnValue({ name: 'voidplugin', conf: {} })35  expect(getResource('testtest')).toEqual(resources.testtest)36})37test('If the plugin has threshold, the resource has `last`', () => {38  findPlugin.mockReturnValue({ conf: { threshold: 100 } })39  expect(getResource('test').last).toBeTruthy()40})41test('If the plugin has checkInterval, the resource has `intervals`', () => {42  findPlugin.mockReturnValue({ conf: { checkInterval: 100 } })43  expect(getResource('test').intervals).toEqual({})44})45test('If the plugin has getResource, is called', () => {46  const plugin = {47    conf: {},48    getResource: jest.fn()49  }50  findPlugin.mockReturnValue(plugin)51  getResource('test')52  expect(plugin.getResource).toHaveBeenCalled()53})54test('the plugin`s getResource can modify the resource', () => {55  findPlugin.mockReturnValue({56    conf: {},57    getResource (resource) {58      resource.modifiedByMe = true59    }60  })61  expect(getResource('test').modifiedByMe).toBe(true)...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

...25	const render = template(config.tagFormat);26	t.is(render({ version }), version);27});28test('config uses commit analyser with peakfijn preset', t => {29	const plugin = findPlugin('@semantic-release/commit-analyzer');30	t.is(plugin.preset, 'peakfijn');31	t.is(plugin.releaseRules, 'release-rules-peakfijn');32});33test('config uses release note generator with peakfijn preset', t => {34	const plugin = findPlugin('@semantic-release/release-notes-generator');35	t.is(plugin.preset, 'peakfijn');36});37test('config uses changelog plugin', t => {38	t.truthy(findPlugin('@semantic-release/changelog'));39});40test('config uses npm plugin', t => {41	t.truthy(findPlugin('@semantic-release/npm'));42});43test('config uses git plugin with predefined message and assets', t => {44	const plugin = findPlugin('@semantic-release/git');45	const assets = [46		'CHANGELOG.md',47		'package.json',48		'package-lock.json',49	];50	// eslint-disable-next-line no-template-curly-in-string51	t.is(plugin.message, 'release: create new version ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}');52	t.true(isEqual(plugin.assets, assets));53});54test('config uses github plugin', t => {55	t.truthy(findPlugin('@semantic-release/github'));56});57test('binary defers call to semantic release', async t => {58	const { stdout: help } = await execa(59		pkg.bin['semantic-release'],60		['--help'],61		{ cwd: __dirname },62	);63	t.true(help.includes('Run automated package publishing'));...

Full Screen

Full Screen

command.js

Source:command.js Github

copy

Full Screen

1import { command } from '../command'2import { resources } from '../conf'3import { findPlugin } from '../../private/findPlugin'4jest.mock('../../private/findPlugin')5jest.spyOn(console, 'warn').mockImplementation()6describe('command', () => {7  beforeEach(() => {8    Object.keys(resources).forEach(key => delete resources[key])9    findPlugin.mockReturnValue({})10  })11  it('calls findPlugin if there is no resource for the url', () => {12    command('some url')13    expect(findPlugin).toHaveBeenCalledWith('some url')14  })15  it('not call findPlugin if there is resource for the url', () => {16    resources.someUrl = { plugin: {} }17    command('someUrl')18    expect(findPlugin).not.toHaveBeenCalled()19  })20  it('warns if the plugin does not accept commands', () => {21    command('some url')22    expect(console.warn).toHaveBeenCalledWith('the plugin does not accept commands')23  })24  it('warns if the plugin accept commands but not this', () => {25    findPlugin.mockReturnValue({26      commands: {}27    })28    command('some url', 'someCommand')29    expect(console.warn).toHaveBeenCalledWith('command not found')30  })31  it('calls the plugin command', () => {32    const someCommand = jest.fn()33    findPlugin.mockReturnValue({34      commands: { someCommand }35    })36    command('some url', 'someCommand', 'parameter', 1, 2, 3)37    expect(someCommand).toHaveBeenCalledWith('some url', 'parameter', 1, 2, 3)38  })39  it('returns the returned value of the plugin command', () => {40    const someCommand = jest.fn().mockReturnValue('OK')41    findPlugin.mockReturnValue({42      commands: { someCommand }43    })44    expect(command('some url', 'someCommand')).toBe('OK')45  })...

Full Screen

Full Screen

get.js

Source:get.js Github

copy

Full Screen

1import { get } from '../get'2import { findPlugin } from '../../private/findPlugin'3import { resources } from '../conf'4jest.mock('../../private/findPlugin')5beforeEach(() => Object.keys(resources).forEach(key => delete resources[key]))6describe('get', () => {7  it('returns the cached value, if exists', () => {8    resources.someUrl = {9      value: 'value'10    }11    expect(get('someUrl')).toBe('value')12  })13  it('calls findPlugin, if there is no cached value', () => {14    findPlugin.mockReturnValue({})15    get('someUrl')16    expect(findPlugin).toHaveBeenCalledWith('someUrl')17  })18  it('returns undefined if there is no plugin', () => {19    findPlugin.mockReturnValue({})20    expect(get('someUrl')).toBeUndefined()21  })22  it('returns the value returned by the plugin', () => {23    const getPlugin = jest.fn(() => 'returnedValue')24    findPlugin.mockImplementation(() => {25      return {26        get: getPlugin27      }28    })29    expect(get('someUrl')).toBe('returnedValue')30    expect(getPlugin).toHaveBeenCalledWith('someUrl')31  })...

Full Screen

Full Screen

Jest Testing Tutorial

LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest 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