本文整理匯總了TypeScript中power-assert.throws函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript throws函數的具體用法?TypeScript throws怎麽用?TypeScript throws使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了throws函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: context
context('number', () => {
const sample = new SampleNumber(1)
assert(sample.val === 1)
assert.throws(() => {
sample.val = 2
})
})
示例2: it
it('should work with exception', function() {
assert.throws(function() {
var naughty = new Obs(function() {
throw "anything"
})
})
assert(caller.callers.length === 1)
})
示例3: assert
import assert from "power-assert";
assert(1 + 1 - 2 === 0, "The universe isn't how it should.");
assert.deepEqual({x: {y: 3}}, {x: {y: 3}}, "DEEP WENT DERP");
assert.equal(3, "3", "uses == comparator");
assert.notStrictEqual(2, "2", "uses === comparator");
assert.deepStrictEqual([{a:1}], [{a:1}], "uses === comparator");
assert.notDeepStrictEqual([{a:1}], [{a:1}], "uses === comparator");
assert.throws(() => {
throw "a hammer at your face";
}, undefined, "DODGED IT");
assert.doesNotThrow(() => {
if (false) {
throw "a hammer at your face";
}
}, undefined, "What the...*crunch*");
var customizedAssert1 = assert.customize({
output: {
maxDepth: 2
}
});
示例4: it
it("should throws an error.", () => {
assert.throws(() => none.get, error => {
assert(error.message === "No such element.");
return true;
});
});
示例5: it
it('should throw an Error when the value does not match any cases', () => {
let f = () => match<number, string>(2, when => when(1, () => 'One'));
assert.throws(f, 'MatchError: Given value does not match any cases');
});
示例6: it
it('generator#throw(e: any)', () => {
const g = Uint32LCG.generator(Uint32LCG.GEN3_ARG, 0x00000000);
assert.throws(() => g.throw(new Error()), '');
assert.throws(() => g.throw(new Error('message')), 'message');
});
示例7: it
it('invalid format', () => {
assert.throws(() => jp.parse('hoge'), /^Error: Invalid JSON-Pointer format:/);
});