How to use the chance function in chance

To help you get started, we’ve selected a few chance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zifeo / Croque / test / helpers.js View on Github external
// @flow

import 'babel-polyfill';
import chai from 'chai';
import Chance from 'chance';
import _ from 'lodash';
import { findGroups, decompose345, findDecomposition } from '../src/helpers';
import type { User } from '../src/db';

const chance = new Chance();

function forgeUser(uniqueid: string, lang: string): User {
  return {
    lang,
    slug: chance.word(),
    firstname: chance.first(),
    name: chance.last(),
    uniqueid,
    email: chance.email(),
    lastSeen: chance.date().toISOString(),
  };
}

const should = chai.should();

describe('Match making', () => {
github sanity-io / sanity / packages / @sanity / components / src / autocomplete / story.js View on Github external
import React from 'react'
import {storiesOf, action} from 'part:@sanity/storybook'
import Autocomplete from 'part:@sanity/components/autocomplete/default'
import {range} from 'lodash'

import Chance from 'chance'
const chance = new Chance()

const formStyle = {width: '30em', margin: '0 auto', paddingBottom: '20em'}

storiesOf('Autocomplete')
  .add(
    'Default',
    // `
    //   Autocomplete is used to help user complete a normal text input. The input can be anything.
    // `,
    () => {
      return (
        <form style="{formStyle}">
          </form>
github elastic / kibana / src / legacy / utils / __tests__ / kbn_field_types.js View on Github external
* You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import expect from 'expect.js';
import Chance from 'chance';

const chance = new Chance();
import {
  KbnFieldType,
  getKbnFieldType,
  castEsToKbnFieldTypeName,
  getKbnTypeNames
} from '../kbn_field_types';

describe('utils/kbn_field_types', () => {
  describe('KbnFieldType', () => {
    it('defaults', () => {
      expect(new KbnFieldType())
        .to.have.property('name', undefined)
        .and.have.property('sortable', false)
        .and.have.property('filterable', false)
        .and.have.property('esTypes').eql([]);
    });
github xilution / xilution-react-todomvc / test / unit / frontend / actions / index.spec.js View on Github external
import Chance from 'chance';

import * as actions from '../../../../src/frontend/actions/index';

const chance = new Chance();

describe('todo action tests', () => {
  test('createTodo should create ADD_TODO action', () => {
    const text = chance.sentence();

    expect(actions.createTodo({ text })).toEqual({
      todo: { text },
      type: 'ADD_TODO',
    });
  });

  test('deleteTodo should create DELETE_TODO action', () => {
    const id = chance.string();

    expect(actions.deleteTodo(id)).toEqual({
      id,
github comindware / core-ui / tests / specs / VirtualCollection.spec.js View on Github external
/*eslint-ignore*/

import Chance from 'chance';
import core from 'coreApi';
import { expectCollectionsToBeEqual, expectToHaveSameMembers } from '../utils/helpers';
import { TaskModel, addChanceMixins } from '../utils/testData';

const chance = new Chance();
const repository = addChanceMixins(chance);

describe('VirtualCollection', () => {
    const assigneeGrouping = {
        modelFactory(model) {
            return model.get('assignee');
        },
        comparator(model) {
            return model.get('assignee').id;
        },
        iterator(model) {
            return model.get('assignee').get('name');
        },
        affectedAttributes: ['assignee']
    };
github notonthehighstreet / toga / src / app / lib / universalRendering / createIsoConfig.spec.js View on Github external
import { expect } from 'chai';
import Chance from 'chance';
import builder from './createIsoConfig';

const chance = new Chance();
const fakeAssetsName = chance.file();
const assetPath = `${chance.word()}/${chance.word()}`;
const subject = builder({
  path: require('path')
});

describe('create iso config', () => {
  it('return json with a path matching the components dir', () => {
    const config = subject(assetPath, fakeAssetsName);
    expect(config.webpack_assets_file_path.endsWith(`${assetPath}/${fakeAssetsName}`)).to.equal(true);
  });
});
github dzdrazil / swagger-mock-api / src / Parsers / NumberParser.js View on Github external
import Chance from 'chance';
const chance = new Chance();

export default class NumberParser {
    canParse(node) {
        return this.isInteger(node) || this.isFloating(node);
    }

    parse(node) {
        if (this.isInteger(node))
            return this.generateInteger(node);

        if (this.isFloating(node))
            return chance.floating(node['x-type-options']);
    }

    generateInteger(node) {
        let bounds = this.resolveBounds(node);
github jquense / react-widgets / packages / storybook / config.js View on Github external
configure(() =&gt; {
  global.Globalize = Globalize;

  let chance = global.chance = new Chance();

  global.generateNames = function(limit = 100) {
    var arr = new Array(limit)

    for(var i = 0; i &lt; arr.length; i++){
      var first = chance.first()
        , last = chance.last()

      arr[i] = {
        first,
        last,
        id: i + 1,
        fullName: `${first} ${last}`,
      }
    }
github mpigsley / sectors-without-number / src / utils / entity-generators / moon-base-generator.js View on Github external
parentEntity,
  name = generateStationName(),
  hideOccAndSit = false,
  generate = true,
  isHidden,
} = {}) => {
  if (!sector) {
    throw new Error('Sector must be defined to generate a moon base');
  }
  if (!parent || !parentEntity) {
    throw new Error(
      'Parent id and type must be defined to generate a moon base',
    );
  }

  const chance = new Chance();
  let asteroidBase = { name, parent, parentEntity, sector };
  if (isHidden !== undefined) {
    asteroidBase = { ...asteroidBase, isHidden };
  }
  if (generate) {
    if (hideOccAndSit) {
      asteroidBase.visibility = {
        'attr.occupation': false,
        'attr.situation': false,
      };
    }
    asteroidBase = {
      ...asteroidBase,
      attributes: {
        occupation: chance.pickone(Object.keys(Occupation.attributes)),
        situation: chance.pickone(Object.keys(Situation.attributes)),
github nunux-keeper / keeper-web-app / src / api / profile / ProfileMock.js View on Github external
import Chance from 'chance'

const chance = new Chance()

function getRandomProfile (_profile = {}) {
  return Object.assign(_profile, {
    hash: chance.hash({length: 15}),
    username: chance.sentence({words: 2}),
    date: chance.date()
  })
}

export class ProfileMock {
  get () {
    return Promise.resolve(getRandomProfile())
  }
}

const instance = new ProfileMock()

chance

Chance - Utility library to generate anything random

MIT
Latest version published 1 year ago

Package Health Score

76 / 100
Full package analysis