• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

TypeScript chance.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中chance.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了default函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: Chance

import Chance from 'chance'
import * as R from 'ramda'

const chance = Chance('bookmarkNodes')

const generateBookmarkNode = (): browser.bookmarks.BookmarkTreeNode => ({
  id: String(chance.integer({min: 1000, max: 9999})),
  ...(chance.bool() ? {parentId: String(chance.integer({min: 1000, max: 9999}))} : null),
  ...(chance.bool() ? {index: chance.integer({min: 1000, max: 9999})} : null),
  ...(chance.bool() ? {url: chance.url()} : null),
  title: chance.word(),
  ...(chance.bool() ? {dateAdded: chance.integer({min: 1500000000000, max: 2000000000000})} : null),
  ...(chance.bool() ?
    {
      dateGroupModified: chance.integer({min: 1500000000000, max: 2000000000000})
    } :
    null),
  ...(chance.bool() ? {unmodifiable: 'managed'} : null)
})

export default R.times(generateBookmarkNode, 100)
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:21,代码来源:bookmarkNodes.ts


示例2: Chance

/* eslint redux-saga/no-unhandled-errors: 'off' */

import Chance from 'chance'
import * as R from 'ramda'
import {call, put, select} from 'redux-saga/effects'

import optionsFixture from '../../../../../common/__fixtures__/options.json'
import * as bookmarkCreators from '../../actions'
import bookmarkTrees from '../__fixtures__/bookmarkTrees'
import {getBookmarkTrees} from '../utils/getters'
import {getRestTreeIds, refreshBookmarkTrees} from './refreshBookmarkTrees'

const chance = Chance('refreshBookmarkTrees')

const getRestTreeIdsResult = [
  '5242',
  '7721',
  '9188',
  '2790',
  '3715',
  '9382',
  '8134',
  '8333',
  '7925'
]

describe('getRestTreeIds', () => {
  test('get all tree ids except first tree', () => {
    expect(getRestTreeIds(bookmarkTrees)).toEqual(getRestTreeIdsResult)
  })
  test('allow empty array', () => {
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:31,代码来源:refreshBookmarkTrees.test.ts


示例3: Chance

import Chance from 'chance'

import * as CST from '../../../constants'
import bookmarkNodes from '../saga/__fixtures__/bookmarkNodes'
import bookmarkTrees from '../saga/__fixtures__/bookmarkTrees'
import * as converters from './converters'

const chance = Chance('converters')

const templateBookmarkInfo = bookmarkTrees[0].children[0]

describe('getIconUrl', () => {
  test('return bookmark url if it is bookmark', () => {
    const url = chance.url()
    expect(
      converters.getIconUrl({
        ...templateBookmarkInfo,
        type: CST.BOOKMARK_TYPES.BOOKMARK,
        url
      })
    ).toBe(`chrome://favicon/${url}`)
  })
  test('return folder icon if it is folder', () => {
    expect(
      converters.getIconUrl({
        ...templateBookmarkInfo,
        type: CST.BOOKMARK_TYPES.FOLDER
      })
    ).toBe('test-file-stub')
  })
  test('return empty string if it is neither bookmark nor folder', () => {
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:31,代码来源:converters.test.ts


示例4: Chance

/* eslint redux-saga/no-unhandled-errors: 'off' */

import Chance from 'chance'
import {call, put} from 'redux-saga/effects'
import {getType} from 'typesafe-actions'

import {queryTabs} from '../../../../../common/utils'
import * as bookmarkCreators from '../../actions'
import {addCurrentPage} from './addCurrentPage'

const chance = Chance('addCurrentPage')

const currentTabs = [
  {
    title: '  title  ',
    url: '  https://google.com/  '
  },
  {
    title: chance.word(),
    url: chance.url()
  }
]

describe('addCurrentPage', () => {
  test('should successfully add current tab as bookmark', () => {
    const index = chance.integer()
    const parentId = String(chance.integer())

    const generator = addCurrentPage({
      type: getType(bookmarkCreators.addCurrentPage),
      payload: {parentId, index}
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:31,代码来源:addCurrentPage.test.ts


示例5: Chance

/* eslint redux-saga/no-unhandled-errors: 'off' */

import Chance from 'chance'
import {put} from 'redux-saga/effects'
import {getType} from 'typesafe-actions'

import * as CST from '../../../../constants'
import * as bookmarkCreators from '../../actions'
import {addSeparator} from './addSeparator'

jest.mock('nanoid', () => () => 'mocked-id')

const chance = Chance('addSeparator')

describe('addSeparator', () => {
  test('should successfully add separator', () => {
    const index = chance.integer()
    const parentId = String(chance.integer())

    const generator = addSeparator({
      type: getType(bookmarkCreators.addSeparator),
      payload: {parentId, index}
    })

    expect(generator.next().value).toEqual(
      put(
        bookmarkCreators.createBookmark(
          parentId,
          index,
          '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -',
          CST.SEPARATE_THIS_URL + '#mocked-id'
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:31,代码来源:addSeparator.test.ts


示例6: cloneableGenerator

/* eslint redux-saga/no-unhandled-errors: 'off' */

import {cloneableGenerator} from '@redux-saga/testing-utils'
import Chance from 'chance'
import {call} from 'redux-saga/effects'
import {getType} from 'typesafe-actions'

import {removeBookmark, removeBookmarkTree} from '../../../../../common/utils'
import * as CST from '../../../../constants'
import * as bookmarkCreators from '../../actions'
import bookmarkTrees from '../__fixtures__/bookmarkTrees'
import {getBookmarkInfo} from '../utils/getters'
import {deleteBookmark} from './deleteBookmark'

const chance = Chance('deleteBookmark')

const createGenerator = (id: string) => {
  return cloneableGenerator(deleteBookmark)({
    type: getType(bookmarkCreators.deleteBookmark),
    payload: {id}
  })
}

describe('deleteBookmark', () => {
  const id = String(chance.integer())
  let generator = createGenerator(id)

  beforeAll(() => {
    generator = createGenerator(id)

    expect(generator.next().value).toEqual(call(getBookmarkInfo, id))
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:31,代码来源:deleteBookmark.test.ts


示例7: Chance

import Chance from 'chance'
import * as R from 'ramda'

import * as CST from '../../../../constants'

const chance = Chance('bookmarkTrees')

const generateType = () =>
  chance.pickone([
    CST.BOOKMARK_TYPES.BOOKMARK,
    CST.BOOKMARK_TYPES.FOLDER,
    CST.BOOKMARK_TYPES.SEPARATOR
  ])

const generateBookmarkInfo = (type?: CST.BOOKMARK_TYPES) => ({
  id: String(chance.integer({min: 1000, max: 9999})),
  parentId: String(chance.integer({min: 1000, max: 9999})),
  title: chance.word(),
  url: chance.url(),
  iconUrl: chance.url(),
  storageIndex: chance.integer({min: -1, max: 9999}),
  type: type || generateType(),
  isRoot: chance.bool(),
  isSimulated: false,
  isUnmodifiable: chance.bool()
})

export const generateBookmarkTree = () => ({
  children: R.times(() => generateBookmarkInfo(), 20),
  parent: generateBookmarkInfo(CST.BOOKMARK_TYPES.FOLDER)
})
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:31,代码来源:bookmarkTrees.ts


示例8: Chance

import Chance from 'chance'
import * as R from 'ramda'
import {call, put, select} from 'redux-saga/effects'
import {getType} from 'typesafe-actions'

import optionsFixture from '../../../../../common/__fixtures__/options.json'
import {OPTIONS} from '../../../../constants'
import * as bookmarkCreators from '../../actions'
import bookmarkTrees from '../__fixtures__/bookmarkTrees'
import searchResult from '../__fixtures__/searchResult'
import searchTitleOnlyResult from '../__fixtures__/searchTitleOnlyResult'
import {searchBookmarks} from '../utils/getters'
import {getSearchResult, searchKeywordMatcher} from './getSearchResult'

const chance = Chance('getSearchResult')

describe('searchKeywordMatcher', () => {
  test('return true if all keywords is matched', () => {
    const searchKeyword = 'a b c'

    expect(searchKeywordMatcher(searchKeyword, 'abc')).toBe(true)
    expect(searchKeywordMatcher(searchKeyword, 'cab')).toBe(true)
    expect(searchKeywordMatcher(searchKeyword, 'cabdefg')).toBe(true)
  })
  test('return false if one of the keywords is not matched', () => {
    const searchKeyword = 'a b c'

    expect(searchKeywordMatcher(searchKeyword, 'ca')).toBe(false)
    expect(searchKeywordMatcher(searchKeyword, 'z')).toBe(false)
    expect(searchKeywordMatcher(searchKeyword, '')).toBe(false)
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:30,代码来源:getSearchResult.test.ts


示例9: Chance

import * as R from 'ramda'
import {all, call} from 'redux-saga/effects'

import optionsFixture from '../../../../../common/__fixtures__/options.json'
import {
  getBookmarkChildNodes,
  getBookmarkNodes,
  searchBookmarkNodes
} from '../../../../../common/utils'
import * as CST from '../../../../constants'
import {BookmarkTree} from '../../../../types'
import bookmarkNodes from '../__fixtures__/bookmarkNodes'
import bookmarkTrees from '../__fixtures__/bookmarkTrees'
import * as getters from './getters'

const chance = Chance('getters')

describe('getBookmarkInfo', () => {
  test('should get the first bookmark node by id and convert it to bookmarkInfo', () => {
    const generator = getters.getBookmarkInfo(bookmarkNodes[0].id)

    expect(generator.next().value).toEqual(call(getBookmarkNodes, bookmarkNodes[0].id))

    expect(generator.next(bookmarkNodes).value).toMatchSnapshot()

    expect(generator.next().done).toBe(true)
  })
})

describe('getBookmarkChildren', () => {
  test('should get all its children by id and convert all children to bookmarkInfo', () => {
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:31,代码来源:getters.test.ts



注:本文中的chance.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript chance.guid函数代码示例发布时间:2022-05-24
下一篇:
TypeScript chance.Chance函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap