本文整理汇总了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:/);
});