本文整理汇总了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;
});
});
示例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();
});
//.........这里部分代码省略.........
示例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',
);
});
});
示例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)
})
})
示例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 });
//.........这里部分代码省略.........