How to use chance - 10 common examples

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 rintoj / ngx-virtual-scroller / demo / src / app / lists / base-list.ts View on Github external
{
	  return this._items;
  }
  public set items(value: ListItem[])
  {
	  this._items = value;
	  this.setToFullList();
  }

  public ListItemComponent = ListItemComponent;
  public randomSize = false;

  public filteredList: ListItem[];

  public static index = 0;
  public static chance = new Chance(0); // 0 = seed for repeatability
  public static generateRandomItem(): ListItem {
	  return {
		  id: BaseList.chance.guid(),
		  index: BaseList.index++,
		  name: BaseList.chance.name(),
		  gender: BaseList.chance.gender(),
		  age: BaseList.chance.age(),
		  email: BaseList.chance.email(),
		  phone: BaseList.chance.phone(),
		  address: BaseList.chance.address() + ', ' + BaseList.chance.city() + ', ' + BaseList.chance.state() + ', ' + BaseList.chance.zip(),
		  company: BaseList.chance.company()
	  };
  }
  
  public static generateMultipleRandomItems(count: number): ListItem[] {
	  let result = Array(count);
github mozilla / fxa / packages / fxa-event-broker / bin / generate-sqs-traffix.ts View on Github external
import Config from '../config';
import { ClientCapabilityService } from '../lib/selfUpdatingService/clientCapabilityService';
import { FactoryBot, LoginEvent, SubscriptionEvent } from '../test/service-notifications';

AWS.config.update({
  region: 'us-east-1'
});

/** Total messages to generate before stopping.
 * @constant {number}
 * @default
 */
const MESSAGE_COUNT = 10_000;

const chance = new Chance();

const sqs = new SQS();
const queueUrl = Config.get('serviceNotificationQueueUrl');
const logger = mozlog(Config.get('log'))('generate-sqs-traffic');

// Promisify the AWS send message, the Node promisify mangled the TS signature
const sqsSendMessage = (params: SQS.SendMessageRequest): Promise =&gt;
  new Promise((resolve, reject) =&gt; {
    sqs.sendMessage(params, (err, data) =&gt; {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    });
  });
github balassy / aws-lambda-typescript / src / cities / cities.service.spec.ts View on Github external
import { expect } from 'chai';
import { Chance } from 'chance';
import { instance, mock, reset, when } from 'ts-mockito';

import { ErrorResult, ForbiddenResult, NotFoundResult } from '../../shared/errors';
import { City, GetCityResult } from './cities.interfaces';
import { CitiesRepository } from './cities.repository';
import { CitiesService } from './cities.service';

// tslint:disable no-unsafe-any (Generates false alarm with ts-mockito functions.)

const chance: Chance.Chance = new Chance();

describe('CitiesService', () => {
  const citiesRepositoryMock: CitiesRepository = mock(CitiesRepository);
  const citiesRepositoryMockInstance: CitiesRepository = instance(citiesRepositoryMock);
  let service: CitiesService;
  let testCity: City;

  beforeEach(() => {
    reset(citiesRepositoryMock);
    service = new CitiesService(citiesRepositoryMockInstance, process.env);
    testCity = {
      country: chance.country(),
      id: chance.natural(),
      name: chance.city(),
      populationDensity: chance.natural()
    };
github UXAspects / UXAspects / docs / app / pages / components / components-sections / notifications / notification-list-ng1 / wrapper / notification-list-wrapper.directive.ts View on Github external
function NotificationListDemoModalCtrl($q: ng.IQService, $scope: ng.IScope, safeTimeout: any, timeAgoService: any) {
    var vm = this;

    var chance = require('chance').Chance();

    // create safe timeout instance
    var safeTimeoutInstance = safeTimeout.create($scope);

    vm.itemTemplateUrl = 'notification-list-ng1/notification.html';

    vm.getPage = function (pageNumber: number, pageSize: number) {
        // return promise to simulate loading from a server
        var defer = $q.defer();

        safeTimeoutInstance.timeout(function () {

            // generate some fake notifications here
            var notifications = [];

            // show a maximimum of 10 pages
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 working-minds / realizejs / test / specs / grid / grid.spec.js View on Github external
describe('', () =&gt; {
  const dummyUrl = '';
  const chance = new Chance();
  let sandbox;

  beforeEach(() =&gt; sandbox = sinon.sandbox.create());
  afterEach(() =&gt; sandbox.restore());

  describe('#constructor', () =&gt; {
    it('is a component', () =&gt; expect(Grid).to.be.a.reactComponent);
  });

  describe('#componentDidMount', () =&gt; {
    it('calls loadData when the props eagerLoad is true', () =&gt; {
      const loadData = sinon.stub(Grid.prototype, 'loadData');
      const withEagerLoad = mount();

      expect(withEagerLoad).to.be.ok;
      expect(loadData).to.have.been.calledOnce;
github gobwas / dm.js / test / unit / dm.js View on Github external
it("should parse config if given", function() {
            var service, definition, services,
                parameter, value, parameters,
                dm;

            (services = {})[(service = chance.word())] = (definition = {});
            (parameters = {})[(parameter = chance.word())] = (value = {});

            dm = new DM(async, loader, {
                parameters: parameters,
                services: services
            });

            expect(dm.getDefinition(service)).equal(definition);
            expect(dm.getParameter(parameter)).equal(value);
        });
    });

chance

Chance - Utility library to generate anything random

MIT
Latest version published 1 year ago

Package Health Score

76 / 100
Full package analysis