本文整理汇总了TypeScript中mocha.it函数的典型用法代码示例。如果您正苦于以下问题:TypeScript it函数的具体用法?TypeScript it怎么用?TypeScript it使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了it函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe(RootApi.name, () => {
it('should add button', () => {
const api = createApi();
const b = api.addButton({
title: 'push',
});
assert.strictEqual(b.controller.button.title, 'push');
});
it('should add folder', () => {
const api = createApi();
const f = api.addFolder({
title: 'folder',
});
assert.strictEqual(f.controller.folder.title, 'folder');
assert.strictEqual(f.controller.folder.expanded, true);
});
it('should add collapsed folder', () => {
const api = createApi();
const f = api.addFolder({
expanded: false,
title: 'folder',
});
assert.strictEqual(f.controller.folder.expanded, false);
});
it('should add separator', () => {
const api = createApi();
api.addSeparator();
const cs = api.controller.uiControllerList.items;
assert.instanceOf(cs[cs.length - 1], SeparatorController);
});
});
示例2: describe
describe(MonitorBindingApi.name, () => {
it('should listen update event', (done) => {
const PARAMS = {
foo: 0,
};
const api = createApi(new Target(PARAMS, 'foo'));
api.on('update', (value) => {
assert.strictEqual(value, 123);
done();
});
PARAMS.foo = 123;
const ticker = api.controller.binding.ticker;
if (ticker instanceof ManualTicker) {
ticker.tick();
}
});
it('should refresh bound value', () => {
const PARAMS = {
foo: 0,
};
const api = createApi(new Target(PARAMS, 'foo'));
PARAMS.foo = 123;
api.refresh();
assert.strictEqual(api.controller.binding.value.rawValues[0], 123);
});
});
示例3: EPub
mocha.describe('EPub', () => {
mocha.it('init', () => {
const epub = new EPub('./example/alice.epub');
assert.strictEqual(
epub.imageroot,
`/images/`
);
});
mocha.it('basic parsing', () => {
const epub = new EPub('./example/alice.epub');
epub.parse();
assert.strictEqual(
epub.imageroot,
`/images/`
);
});
mocha.it('supports empty chapters', () => {
var branch = [{navLabel: { text: '' }}];
const epub = new EPub();
var res = epub.walkNavMap(branch, [], []);
assert.ok(res);
});
});
示例4: describe
describe('create', () => {
it('should create an image with n o background', async () => {
const output = 'create-blank.png';
await run('create', '-w', '100', '--he', '200', '-o', output);
fs.readFileSync(output).should.be.deepEqual(
fs.readFileSync(makePath(__dirname, `./images/${output}`))
);
fs.unlinkSync(output);
});
it('should create an image with a background', async () => {
const output = 'create.png';
await run(
'create',
'-w',
'100',
'--he',
'200',
'-b',
0xff0000ff,
'-o',
output
);
fs.readFileSync(output).should.be.deepEqual(
fs.readFileSync(makePath(__dirname, `./images/${output}`))
);
fs.unlinkSync(output);
});
});
示例5: describe
describe(StepConstraint.name, () => {
it('should constrain value with step', () => {
const c = new StepConstraint({
step: 1,
});
assert.closeTo(c.constrain(-0.51), -1, DELTA);
assert.closeTo(c.constrain(-0.5), -1, DELTA);
assert.closeTo(c.constrain(-0.49), 0, DELTA);
assert.closeTo(c.constrain(0), 0, DELTA);
assert.closeTo(c.constrain(1.49), 1, DELTA);
assert.closeTo(c.constrain(1.5), 2, DELTA);
assert.closeTo(c.constrain(1.51), 2, DELTA);
});
it('should constrain value with decimal step', () => {
const c = new StepConstraint({
step: 0.2,
});
assert.closeTo(c.constrain(-1.51), -1.6, DELTA);
assert.closeTo(c.constrain(-1.5), -1.6, DELTA);
assert.closeTo(c.constrain(-1.49), -1.4, DELTA);
assert.closeTo(c.constrain(0), 0, DELTA);
assert.closeTo(c.constrain(1.49), 1.4, DELTA);
assert.closeTo(c.constrain(1.5), 1.6, DELTA);
assert.closeTo(c.constrain(1.51), 1.6, DELTA);
});
it('should get step', () => {
const c = new StepConstraint({
step: 0.2,
});
assert.strictEqual(c.step, 0.2);
});
});
示例6: describe
describe('Preset', () => {
it('should export JSON', () => {
const PARAMS = {
bar: 'hello',
foo: 1,
};
const preset = Preset.exportJson([
new Target(PARAMS, 'foo'),
new Target(PARAMS, 'bar'),
]);
assert.deepStrictEqual(preset, {
bar: 'hello',
foo: 1,
});
});
it('should import JSON', () => {
const PARAMS = {
bar: 'hello',
foo: 1,
};
const targets = [new Target(PARAMS, 'foo'), new Target(PARAMS, 'bar')];
const preset = Preset.exportJson(targets);
preset.foo = 123;
preset.bar = 'world';
Preset.importJson(targets, preset);
assert.strictEqual(PARAMS.foo, 123);
assert.strictEqual(PARAMS.bar, 'world');
});
});
示例7: describe
describe(TextInputController.name, () => {
it('should get value', () => {
const value = new InputValue(0);
const doc = TestUtil.createWindow().document;
const c = new TextInputController(doc, {
formatter: new NumberFormatter(2),
parser: NumberParser,
value: value,
});
assert.strictEqual(c.value, value);
});
it('should apply input to value', () => {
const value = new InputValue(0);
const win = TestUtil.createWindow();
const doc = win.document;
const c = new TextInputController(doc, {
formatter: new NumberFormatter(2),
parser: NumberParser,
value: value,
});
c.view.inputElement.value = '3.14';
c.view.inputElement.dispatchEvent(new (win as any).Event('change'));
assert.strictEqual(c.value.rawValue, 3.14);
});
});
示例8: describe
describe('Context', () => {
it('exposes simple bindings', () => {
let context = new Context();
assert.ok(context.bind('foo', 1));
assert.ok(context.bind('foo', 1));
assert.notOk(context.bind('foo', 2));
assert.deepEqual(flattenPrototype(context.expose()), { foo: 1 });
});
it('exposes and can discard provisional bindings', () => {
let context = new Context();
assert.ok(context.bind('foo', 1));
let provisional = context.createProvisionalContext();
assert.notOk(provisional.bind('foo', 2));
assert.ok(provisional.bind('bar', 3));
assert.deepEqual(flattenPrototype(context.expose()), { foo: 1 });
assert.deepEqual(flattenPrototype(provisional.expose()), { foo: 1, bar: 3 });
provisional.commit();
assert.deepEqual(flattenPrototype(context.expose()), { foo: 1, bar: 3 });
});
});
示例9: describe
describe('buildStateProxyObject', () => {
it('Should proxy state getter', () => {
const initialState = {
message: 'messageValue'
};
const result = buildStateProxyObject(initialState, null, key => initialState[key]);
assert.ok(result.message);
assert.equal(result.message, 'messageValue');
});
it('Should proxy to models', () => {
const model: IModel = {
$state: { message2: 'message2Value' },
signals: {},
models: {}
};
const models = {
submodel: model
}
const result = buildStateProxyObject(null, models, null);
assert.ok(result.submodel, 'submodel');
assert.ok(result.submodel.message2, 'submodel.message2');
assert.equal(result.submodel.message2, 'message2Value');
});
});
示例10: describe
describe('ColorConverter', () => {
it('should convert mixed to color', () => {
// tslint:disable:object-literal-sort-keys
assert.deepStrictEqual(ColorConverter.fromMixed('#112233').toObject(), {
r: 0x11,
g: 0x22,
b: 0x33,
});
assert.deepStrictEqual(ColorConverter.fromMixed('foobar').toObject(), {
r: 0,
g: 0,
b: 0,
});
assert.deepStrictEqual(ColorConverter.fromMixed(123).toObject(), {
r: 0,
g: 0,
b: 0,
});
});
it('should convert color to string', () => {
assert.strictEqual(ColorConverter.toString(new Color(0, 0, 0)), '#000000');
assert.strictEqual(
ColorConverter.toString(new Color(0, 127, 255)),
'#007fff',
);
assert.strictEqual(
ColorConverter.toString(new Color(255, 255, 255)),
'#ffffff',
);
});
});
示例11: describe
describe('diff helper', () => {
it('diff helper', done => {
setUpCli(['diff', testImage1, testImage2], (output, result) => {
output.should.be.exactly('diff');
result.should.be.exactly(0.9747570461662795);
done();
}).argv;
});
it('outputs a diff image to default path', done => {
setUpCli(['diff', testImage1, testImage2, '-o'], () => {}).argv;
setTimeout(() => {
fs.existsSync('diff.png').should.be.exactly(true);
fs.unlinkSync('diff.png');
done();
}, 1000);
});
it('outputs a diff image to default path', done => {
setUpCli(['diff', testImage1, testImage2, '-o', 'custom.png'], () => {})
.argv;
setTimeout(() => {
fs.existsSync('custom.png').should.be.exactly(true);
fs.unlinkSync('custom.png');
done();
}, 2000);
});
});
示例12: describe
describe(PaneError.name, () => {
it('should instanciate for invalid parameters', () => {
const e = new PaneError({
context: {
name: 'foo',
},
type: 'invalidparams',
});
assert.strictEqual(e.type, 'invalidparams');
});
it('should instanciate for no matching controller', () => {
const e = new PaneError({
context: {
key: 'foo',
},
type: 'nomatchingcontroller',
});
assert.strictEqual(e.type, 'nomatchingcontroller');
});
it('should instanciate for empty value', () => {
const e = new PaneError({
context: {
key: 'foo',
},
type: 'emptyvalue',
});
assert.strictEqual(e.type, 'emptyvalue');
});
});
示例13: 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;
});
});
示例14: describe
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');
});
});
示例15: describe
describe('.textFromHtml', () => {
it('should not change unformatted text', () => {
expect(textFromHtml('hi there, this is some text. <>!@#$%^&*()_+{}|[]')).to.eql('hi there, this is some text. <>!@#$%^&*()_+{}|[]');
});
it('should convert <em>...</em> to _..._', () => {
expect(textFromHtml('<em>emphasis</em>')).to.eql('_emphasis_');
expect(textFromHtml('this is <em>emphasis</em>...')).to.eql('this is _emphasis_...');
expect(textFromHtml('<em><>!@#$%^&*()_+{}|[]</em>')).to.eql('_<>!@#$%^&*()_+{}|[]_');
});
it('should convert <strong>...</strong> to **...**', () => {
expect(textFromHtml('<strong>strong</strong>')).to.eql('**strong**');
expect(textFromHtml('this is <strong>strong</strong>...')).to.eql('this is **strong**...');
expect(textFromHtml('<strong><>!@#$%^&*()_+{}|[]</strong>')).to.eql('**<>!@#$%^&*()_+{}|[]**');
});
it('should convert <a href="x">y</a> to [y](x)', () => {
expect(textFromHtml('<a href="http://luketurner.org">link</a>')).to.eql('[link](http://luketurner.org)');
expect(textFromHtml('this is a <a href="http://luketurner.org">link</a>.')).to.eql('this is a [link](http://luketurner.org).');
expect(textFromHtml('<a href="http://luketurner.org"><>!@#$%^&*()_+{}|[]</a>')).to.eql('[<>!@#$%^&*()_+{}|[]](http://luketurner.org)');
});
it('should convert <a href="#tag"> to #tag', () => {
expect(textFromHtml('<a href="#tag">#tag</a>')).to.eql('#tag');
expect(textFromHtml('this is a <a href="#tag">#tag</a>...')).to.eql('this is a #tag...');
});
});