本文整理匯總了TypeScript中@ephox/bedrock.assert類的典型用法代碼示例。如果您正苦於以下問題:TypeScript assert類的具體用法?TypeScript assert怎麽用?TypeScript assert使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了assert類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: clearHistory
UnitTest.test('HistoryTest', () => {
const filetype = 'test';
clearHistory();
assert.eq([], getHistory(filetype));
addToHistory('http://example.com', filetype);
assert.eq(['http://example.com'], getHistory(filetype));
// non-http/https urls will be silently discarded
addToHistory('#id', filetype);
assert.eq(['http://example.com'], getHistory(filetype));
// new urls will be put at the front
addToHistory('https://tiny.cloud', filetype);
assert.eq(['https://tiny.cloud', 'http://example.com'], getHistory(filetype));
// existing urls will be moved to the front
addToHistory('http://example.com', filetype);
assert.eq(['http://example.com', 'https://tiny.cloud'], getHistory(filetype));
// only 5 urls will be kept
for (let i = 1; i <= 5; i++) {
addToHistory('http://example.com/' + i + '/', filetype);
}
assert.eq(['http://example.com/5/', 'http://example.com/4/', 'http://example.com/3/', 'http://example.com/2/', 'http://example.com/1/'], getHistory(filetype));
// multiple types of history can be kept independently
const filetype2 = 'test2';
assert.eq([], getHistory(filetype2));
addToHistory('http://www.abc.net.au/news/', filetype2);
assert.eq(['http://www.abc.net.au/news/'], getHistory(filetype2));
assert.eq(['http://example.com/5/', 'http://example.com/4/', 'http://example.com/3/', 'http://example.com/2/', 'http://example.com/1/'], getHistory(filetype));
});
示例2: function
const assertInfo = function (label, expected, info) {
assert.eq(
expected.current,
info.current,
'Test: ' + label + '. Expected current: ' + expected.current + ', but was: ' + info.current
);
assert.eq(
expected.values,
info.values,
'Test: ' + label + '. Expected values: ' + expected.values + ', but was: ' + info.values
);
};
示例3:
Obj.each(expected.pattern, (value, key) => {
if (Obj.has<any, string>(pattern, key)) {
Assertions.assertEq('Pattern ' + (i + 1) + ' property `' + key + '` is not equal', value, pattern[key]);
} else {
assert.fail('Pattern ' + (i + 1) + ' property `' + key + '` is missing');
}
});
示例4: function
const testCalcSmallContentRect = function () {
const contentAreaRect = rect(0, 0, 25, 25);
const targetRect = rect(40, 0, 10, 10);
const panelRect = rect(0, 20, 50, 50);
const foundRect = Layout.calc(targetRect, contentAreaRect, panelRect);
assert.eq(foundRect, { rect: rect(20, 10, 50, 50), position: 'bc-tc' });
};
示例5: convertUnit
const check = (expected: Option<number>, size: Size, unit: SizeUnit) => {
const result = convertUnit(size, unit);
assert.eq(
true, expected.equals(result),
'Expected conversion of ' + JSON.stringify(size) +
' to ' + unit + ' = ' + result.toString()
);
};
示例6: function
const testIsNumber = function () {
assert.eq(Type.isNumber('a'), false);
assert.eq(Type.isNumber(null), false);
assert.eq(Type.isNumber(undefined), false);
assert.eq(Type.isNumber(true), false);
assert.eq(Type.isNumber(0), true);
assert.eq(Type.isNumber([]), false);
assert.eq(Type.isNumber({}), false);
assert.eq(Type.isNumber(function () { }), false);
};