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

TypeScript mocha.describe函数代码示例

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

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



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

示例1: describe

describe(Foldable.name, () => {
	it('should get initial expanded', () => {
		const f = new Foldable();
		assert.strictEqual(f.expanded, false);
	});

	it('should set expanded', () => {
		const f = new Foldable();
		f.expanded = true;
		assert.strictEqual(f.expanded, true);
	});

	it('should emit change event', (done) => {
		const f = new Foldable();
		f.emitter.on('change', () => {
			done();
		});
		f.expanded = true;
	});

	it('should not emit change event for no changes', () => {
		const f = new Foldable();
		f.expanded = true;

		f.emitter.on('change', () => {
			throw new Error('should not be called');
		});
		f.expanded = true;
	});
});
开发者ID:cocopon,项目名称:tweakpane,代码行数:30,代码来源:foldable-test.ts


示例2: describe

describe("Callcc", () => {
  it("should return current env", () => {
    function receiver(_, _c, _cerr, env) {
      assert.equal(env.values.answer, 42);
      assert.equal(env.values.callWithCurrentContinuation, callWithCurrentContinuation);
    }
    metaesEval(
      "var answer=42; callWithCurrentContinuation(receiver)",
      console.log,
      e => {
        throw e;
      },
      { callWithCurrentContinuation, receiver }
    );
  });

  it("should call with current continuation with additional arguments", async () => {
    const context = new MetaesContext(undefined, undefined, {
      values: { callWithCurrentContinuation, receiver }
    });

    let env;
    function receiver(_, cc, _cerr, environment) {
      // remember environment for later check
      env = environment;
      // intentionally continue a bit later
      setTimeout(cc, 0, 21);
    }

    const result = await evalFunctionBodyAsPromise({
      context,
      source: callWithCurrentContinuation => 2 * callWithCurrentContinuation(receiver)
    });
    assert.equal(result, 42);
    assert.containsAllKeys(env, ["values"]);
  });

  it("should continue after call/cc multiple times if user decides to", async () => {
    const result = [];
    const context = new MetaesContext(undefined, undefined, {
      values: { callcc: callWithCurrentContinuation, receiver, result }
    });
    let cc;
    function receiver(_, _cc) {
      cc = _cc;
      cc([1, 2, 3]);
    }
    await evalFunctionBodyAsPromise({
      context,
      source: (callcc, result, receiver) => {
        for (let x of callcc(receiver)) {
          result.push(x);
        }
      }
    });
    assert.deepEqual(result, [1, 2, 3]);
    cc([4, 5, 6]);
    assert.deepEqual(result, [1, 2, 3, 4, 5, 6]);
  });

  it(`should continue after call/cc multiple times if user decides to. 
      Should execut first time using passed in value`, async () => {
    const result = [];
    const context = new MetaesContext(undefined, undefined, {
      values: { callcc: callWithCurrentContinuation, receiver, result }
    });
    let cc;
    function receiver(value, _cc, _cerr) {
      cc = _cc;
      cc(value);
    }
    await evalFunctionBodyAsPromise({
      context,
      source: (callcc, result, receiver) => {
        const bind = value => callcc(receiver, value);
        for (let x of bind([1, 2, 3])) {
          result.push(x);
        }
      }
    });
    assert.deepEqual(result, [1, 2, 3]);
    // rerun loop
    cc([4, 5, 6]);
    assert.deepEqual(result, [1, 2, 3, 4, 5, 6]);
  });

  it("should accept metaes function as call/cc receiver", async () => {
    const context = new MetaesContext(undefined, undefined, {
      values: { callcc: callWithCurrentContinuation, console }
    });

    const i = await evalFunctionAsPromise({
      context,
      source: callcc => {
        let evilGoTo;
        let i = 0;
        callcc(function(_, cc) {
          evilGoTo = cc;
          evilGoTo();
        });
//.........这里部分代码省略.........
开发者ID:metaes,项目名称:metaes,代码行数:101,代码来源:callcc.spec.ts


示例3: describe

describe(MonitorBinding.name, () => {
	it('should get value', () => {
		const obj = {
			foo: 123,
		};
		const target = new Target(obj, 'foo');
		const value = new MonitorValue(1);
		const ticker = new ManualTicker();
		const b = new MonitorBinding({
			reader: NumberConverter.fromMixed,
			target: target,
			ticker: ticker,
			value: value,
		});

		assert.strictEqual(b.value, value);
	});

	it('should bind value', () => {
		const obj = {
			foo: 123,
		};
		const target = new Target(obj, 'foo');
		const value = new MonitorValue(1);
		const ticker = new ManualTicker();
		// tslint:disable-next-line:no-unused-expression
		new MonitorBinding({
			reader: NumberConverter.fromMixed,
			target: target,
			ticker: ticker,
			value: value,
		});

		assert.strictEqual(
			value.rawValues[0],
			123,
			'Initial value of target should be applied',
		);

		obj.foo = 456;
		ticker.tick();

		assert.strictEqual(
			value.rawValues[0],
			456,
			'Binded value should be updated',
		);
	});

	it('should bind value', () => {
		const obj = {
			foo: 123,
		};
		const target = new Target(obj, 'foo');
		const value = new MonitorValue(1);
		const ticker = new ManualTicker();
		// tslint:disable-next-line:no-unused-expression
		new MonitorBinding({
			reader: NumberConverter.fromMixed,
			target: target,
			ticker: ticker,
			value: value,
		});

		assert.strictEqual(
			value.rawValues[0],
			123,
			'Initial value of target should be applied',
		);

		delete obj.foo;
		ticker.tick();

		assert.strictEqual(
			value.rawValues[0],
			123,
			'Deleted value should be pushed',
		);
	});
});
开发者ID:cocopon,项目名称:tweakpane,代码行数:80,代码来源:monitor-test.ts


示例4: describe

import { ensure } from 'charly/testHelper'
import { CInteger, CList } from 'charly/types'
import { describe, it } from 'mocha'

// tslint:disable:no-unused-expression

describe('r - reverse/reverseInt', () => {
  it('[lst] => [lst]', () => {
    ensure`r`.withInput`abc`.returns`cba`.withStack(CList)
    ensure`r`.withInput`bb`.returns`bb`.withStack(CList)
    ensure`r`.withInput`a`.returns`a`.withStack(CList)
    ensure`[1 2 3]r`.returns`321`.withStack(CList)
    ensure`[[1 2][3 4]"ab"]r`.returns`ab3412`.withStack(CList)
    ensure`Er`.returns``.withStack(CList)
  })

  it('[int] => [int]', () => {
    ensure`12r`.returns`21`.withStack(CInteger)
    ensure`1r`.returns`1`.withStack(CInteger)
    ensure`10r`.returns`1`.withStack(CInteger)
  })
})
开发者ID:DenkerAffe,项目名称:IPOS,代码行数:22,代码来源:r.spec.ts


示例5: describe

describe('Binding matchers', () => {
  describe('simple()', () => {
    it('accepts the right stuff', () => {
      assertMatch(simple, null);
      assertMatch(simple, undefined);
      assertMatch(simple, false);
      assertMatch(simple, true);
      assertMatch(simple, 'hello');
      assertMatch(simple, 87);
      assertMatch(simple, new class {});
    });

    it('rejects the right stuff', () => {
      assertNoMatch(simple, [1, 2, 3]);
      assertNoMatch(simple, { x: 1, y: 2 });
      assertNoMatch(simple, []);
      assertNoMatch(simple, {});
    });
  });

  describe('choice()', () => {
    let oneOf = (options: any[]) => (name: string) => choice(options, name);

    it('accepts the right stuff', () => {
      assertMatch(oneOf([null, undefined]), null);
      assertMatch(oneOf([null, undefined]), undefined);
      assertMatch(oneOf([true, false]), false);
      assertMatch(oneOf([true, false]), true);
      assertMatch(oneOf(['hello']), 'hello');
      assertMatch(oneOf([87]), 87);
    });

    it('rejects the right stuff', () => {
      assertNoMatch(oneOf([1, 2, 3]), 4);
      assertNoMatch(oneOf([1, 2, 3]), '1');
      assertNoMatch(oneOf([null, false]), undefined);
      assertNoMatch(oneOf([null, false]), '');
      assertNoMatch(oneOf([null, false]), []);
      assertNoMatch(oneOf([]), null);
      assertNoMatch(oneOf([]), undefined);
      assertNoMatch(oneOf([]), false);
      assertNoMatch(oneOf([]), '');
      assertNoMatch(oneOf([]), []);
    });
  });

  describe('sequence()', () => {
    it('accepts the right stuff', () => {
      assertMatch(sequence, [1, 2, 3]);
      assertMatch(sequence, ['hi', false, new class {}]);
      assertMatch(sequence, []);
      assertMatch(sequence, [null]);
    });

    it('rejects the right stuff', () => {
      assertNoMatch(sequence, null);
      assertNoMatch(sequence, 'sequence');
      assertNoMatch(sequence, [{}]);
      assertNoMatch(sequence, [[]]);
      assertNoMatch(sequence, [[1, 2, 3]]);
    });
  });

  describe('match()', () => {
    let matchRegex = (regex: RegExp) => (name: string) => match(regex, name);

    it('accepts the right stuff', () => {
      assertMatch(matchRegex(/b/), 'abc', ['b']);
      assertMatch(matchRegex(/abc/), 'abc', ['abc']);
      assertMatch(matchRegex(/\d+/), 123, ['123']);
      assertMatch(matchRegex(/a(b|c)d/), 'abd', ['b', 'abd']);
      assertMatch(matchRegex(/a(b|c)d/), 'acd', ['c', 'acd']);
      assertMatch(matchRegex(/(a(bc(de)f))(g)/), 'abcdefg', ['abcdef', 'bcdef', 'de', 'g', 'abcdefg']);
      assertMatch(matchRegex(/.*/), undefined, ['undefined']);
      assertMatch(matchRegex(/.*/), null, ['null']);
      assertMatch(matchRegex(/.*/), true, ['true']);
      assertMatch(matchRegex(/.*/), new class {}, ['[object Object]']);
      assertMatch(matchRegex(/.*/), new class { toString() { return 'hi'; } }, ['hi']);
    });

    it('rejects the right stuff', () => {
      assertNoMatch(matchRegex(/.*/), {});
      assertNoMatch(matchRegex(/.*/), []);
      assertNoMatch(matchRegex(/foo/), '');
      assertNoMatch(matchRegex(/abc/), null);
      assertNoMatch(matchRegex(/^abc$/), 'abcd');
    });
  });

  describe('subtree()', () => {
    it('accepts anything', () => {
      assertMatch(subtree, null);
      assertMatch(subtree, undefined);
      assertMatch(subtree, false);
      assertMatch(subtree, true);
      assertMatch(subtree, 'hello');
      assertMatch(subtree, 87);
      assertMatch(subtree, new class {});
      assertMatch(subtree, [1, 2, 3]);
      assertMatch(subtree, { x: 1, y: 2 });
//.........这里部分代码省略.........
开发者ID:salsify,项目名称:botanist,代码行数:101,代码来源:binding-matchers-test.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript mocha.it函数代码示例发布时间:2022-05-25
下一篇:
TypeScript mocha.beforeEach函数代码示例发布时间: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