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

TypeScript mocks.createVariable函数代码示例

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

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



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

示例1: it

    it(`should filter vars with shared prefix: ${example.name}`, () => {
      const target = createVariable('target', 'match me!')
      const partial = createVariable('tar', 'broke!')
      const vars = [example, target, partial]

      const actual = exportVariables([example], vars)

      expect(actual).toEqual([example, target])
    })
开发者ID:influxdata,项目名称:influxdb,代码行数:9,代码来源:exportVariables.test.ts


示例2: describe

describe('exportVariables', () => {
  it('should find dependent variables', () => {
    const a = createVariable('a', 'f(x: v.b)')
    const b = createVariable('b', 'cool')
    const c = createVariable('c', 'nooo!')

    const vars = [a, b, c]

    const actual = exportVariables([a], vars)

    expect(actual).toEqual([a, b])
  })

  it('should find dependent variables with cycles', () => {
    const a = createVariable('a', 'f(x: v.b, y: v.c)')
    const b = createVariable('b', 'f(x: v.f, y: v.e)')
    const c = createVariable('c', 'f(x: v.g)')
    const d = createVariable('d', 'nooooo!')
    const e = createVariable('e', 'pick')
    const f = createVariable('f', 'f(x: v.a, y: v.b)')
    const g = createVariable('g', 'yay')
    const h = createVariable('h', 'nooooo!')

    const vars = [a, b, c, d, e, f, g, h]

    const actual = exportVariables([a], vars)
    const expected = new Set([a, b, c, e, f, g])

    expect(new Set(actual)).toEqual(expected)
  })

  const examples = [
    createVariable('alone', 'v.target'),
    createVariable('space', '\tv.target\n'),
    createVariable('func', 'f(x: v.target)'),
    createVariable('brackets', '[v.target, other]'),
    createVariable('braces', '(v.target)'),
    createVariable('add', '1+v.target-2'),
    createVariable('mult', '1*v.target/2'),
    createVariable('mod', '1+v.target%2'),
    createVariable('bool', '1>v.target<2'),
    createVariable('assignment', 'x=v.target\n'),
    createVariable('curly', '{beep:v.target}\n'),
    createVariable('arrow', '(r)=>v.target==r.field\n'),
    createVariable('comment', '\nv.target//wat?'),
    createVariable('not equal', 'v.target!=r.field'),
    createVariable('like', 'other=~v.target'),
  ]

  examples.forEach(example => {
    it(`should filter vars with shared prefix: ${example.name}`, () => {
      const target = createVariable('target', 'match me!')
      const partial = createVariable('tar', 'broke!')
      const vars = [example, target, partial]

      const actual = exportVariables([example], vars)

      expect(actual).toEqual([example, target])
    })
  })
})
开发者ID:influxdata,项目名称:influxdb,代码行数:61,代码来源:exportVariables.test.ts


示例3: it

    it('converts a variable with dependencies to a template', () => {
      const a = {
        ...createVariable('a', 'x.b + 1'),
        labels: [myfavelabel],
      }
      const b = createVariable('b', '9000')
      const dependencies = [a, b]

      const actual = variableToTemplate(myVariable, dependencies)

      const expected = {
        meta: {
          version: '1',
          name: 'beep-Template',
          description: 'template created from variable: beep',
        },
        content: {
          data: {
            type: 'variable',
            id: '039ae3b3b74b0000',
            attributes: {
              name: 'beep',
              arguments: {
                type: 'query',
                values: {
                  query: 'f(x: v.a)',
                  language: 'flux',
                },
              },
              selected: null,
            },
            relationships: {
              variable: {
                data: [
                  {
                    id: 'a',
                    type: 'variable',
                  },
                  {
                    id: 'b',
                    type: 'variable',
                  },
                ],
              },
              label: {
                data: [],
              },
            },
          },
          included: [
            {
              type: 'variable',
              id: 'a',
              attributes: {
                name: 'a',
                arguments: {
                  type: 'query',
                  values: {
                    query: 'x.b + 1',
                    language: 'flux',
                  },
                },
                selected: [],
              },
              relationships: {
                label: {
                  data: [
                    {
                      type: 'label',
                      id: '1',
                    },
                  ],
                },
              },
            },
            {
              type: 'variable',
              id: 'b',
              attributes: {
                name: 'b',
                arguments: {
                  type: 'query',
                  values: {
                    query: '9000',
                    language: 'flux',
                  },
                },
                selected: [],
              },
              relationships: {
                label: {
                  data: [],
                },
              },
            },
            {
              id: '1',
              type: 'label',
              attributes: {
                name: '1label',
//.........这里部分代码省略.........
开发者ID:sebito91,项目名称:influxdb,代码行数:101,代码来源:resourceToTemplate.test.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript selectors.extractVariablesList函数代码示例发布时间:2022-05-25
下一篇:
TypeScript actions.refreshVariableValues函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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