it('should throw TypeError when set secure on not secure request', () => { const ctx = app.mockContext(); assert.throws(() => { ctx.cookies.set('foo', 'bar', { secure: true }); }, /Cannot send secure cookie over unencrypted connection/); });
it('should throw TypeError when set encrypt on keys not exists', () => { mm(app, 'keys', null); const ctx = app.mockContext(); assert.throws(() => { ctx.cookies.set('foo', 'bar', { encrypt: true, }); }, /\.keys required for encrypt\/sign cookies/); });
it('should throw error when plugin not exists', () => { assert.throws(function() { const baseDir = utils.getFilepath('apps/loader-plugin-noexist'); const appLoader = new AppWorkerLoader({ baseDir, app, logger, }); appLoader.loadConfig(); }, /Can not find plugin noexist in /); });
describe('create application', () => { it('should throw options.baseDir required', () => { assert.throws(() => { new Application({ baseDir: 1, }); }, /options.baseDir required, and must be a string/); }); it('should throw options.baseDir not exist', () => { assert.throws(() => { new Application({ baseDir: 'not-exist', }); }, /Directory not-exist not exists/); }); it('should throw options.baseDir is not a directory', () => { assert.throws(() => { new Application({ baseDir: __filename, }); }, /is not a directory/); }); });
it('should throw TypeError when get encrypt on keys not exists', () => { mm(app, 'keys', null); const ctx = app.mockContext(); ctx.header.cookie = 'foo=bar'; assert.throws(() => { ctx.cookies.get('foo', { encrypt: true, }); }, /\.keys required for encrypt\/sign cookies/); });
it('“某省、某市、某县、某镇” 不存在', () => { assert.throws(() => pcas['某省']['某市']['某县'].indexOf('某镇') !== -1) })
function test() { assert.throws(mightThrow.bind(null), 'should throw on empty parameter'); assert.doesNotThrow( mightThrow.bind(null, 'some-value'), 'should not throw if not empty' ); assert.deepStrictEqual( mightThrow('some-value'), 'some-value', 'should return input if set' ); }
describe('test/grpc/proto_util.test.js', () => { it('should ok', () => { let methodInfo = ProtoUtil.getMethodInfo(proto, 'helloworld.Greeter', 'SayHello'); assert(methodInfo); methodInfo = ProtoUtil.getMethodInfo(proto, 'helloworld.Greeter', 'SayHello'); assert(methodInfo); assert.throws(() => { ProtoUtil.getMethodInfo(proto, 'helloworld.Greeter', 'SayGoodbye'); }, /no such Method 'SayGoodbye' in Service 'helloworld\.Greeter'/); }); });
tom.test('.explainSync: invalid doclet syntax', function () { a.throws( function () { const input = path.resolve(__dirname, 'fixture', 'buggy', 'bad-doclet-syntax.js') jsdoc.explainSync({ files: input }) }, function (err) { return err.name === 'JSDOC_ERROR' } ) })
it ('should throw an error on wrong constructor arguments', function () { assert.throws(function () {new AssignmentNode()}, TypeError ); assert.throws(function () {new AssignmentNode(new Node(), new Node())}, TypeError ); assert.throws(function () {new AssignmentNode('a', new Node())}, TypeError ); assert.throws(function () {new AssignmentNode(2, new Node())}, TypeError ); assert.throws(function () {new AssignmentNode(new Node(), new Node(), new Node())}, TypeError ); });
it('should throw if a target is not provided', () => { assert.throws(() => { zone.createAutoscaler(NAME, {}, assert.ifError); }, /Cannot create an autoscaler without a target\./); });
it('should throw recursive deps error', () => { assert.throws(function() { const baseDir = utils.getFilepath('apps/loader-plugin-dep-recursive'); const appLoader = new AppWorkerLoader({ baseDir, app, logger, }); appLoader.loadConfig(); }, /sequencify plugins has problem, missing: \[\], recursive: \[a,b,c,a\]/); });
it('should throw error when app baseDir not exists', () => { assert.throws(function() { const baseDir = utils.getFilepath('apps/notexist-app'); const appLoader = new AppWorkerLoader({ baseDir, app, logger, }); appLoader.loadConfig(); }, /notexist-app not exists/); });
it('should throw error when plugin dep not exists', function() { assert.throws(function() { const baseDir = utils.getFilepath('apps/loader-plugin-dep-missing'); const appLoader = new AppWorkerLoader({ baseDir, app, logger, }); appLoader.loadConfig(); }, /sequencify plugins has problem, missing: \[a1\], recursive: \[\]\s+>> Plugin \[a1\] is disabled or missed, but is required by \[c\]/); });