當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mocha.describe函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。