// the same as Model.all it('.find()', async function() { const posts = await Post.find(); expect(posts.length).to.be(3); expect(posts.map(post => post.title)).to.contain('New Post'); });
it('support sub template compile', function () { var tpl = '{{include ("./x")}}'; var code = XTemplate.Compiler.compileToStr({ content: tpl, isModule: true }); // do not use require ... expect(code).to.contain('requ'+'ire("./x")'); });
it('.find([ id ])', async function() { const postIds = (await Post.all).map(post => post.id); const posts = await Post.find(postIds); expect(posts.map(post => post.title)).to.contain('New Post'); });
it('can report error', function (done) { var tpl = '\n{{tms(1)}}3'; expect(new XTemplate(tpl, { name: 'report.xtpl', commands: { 'tms': function (scope, option, buffer) { return buffer.async(function (asyncBuffer) { setTimeout(function () { asyncBuffer.error('report error'); }, 100); }); } } }).render({}, function (error) { expect(error.message).to.contain('report.xtpl at line 2'); done(); })).to.equal(''); });
.on('complete', function () { try { expect(this.filter('fastest').pluck('name')).to.contain('require("urlite").parse') done() } catch (e) {
const json = Bone.uncast({test:1}, JSON); expect(json).to.be.a('string'); expect(json).to.contain('test');
it('static function getSignature', function () { var queries = { a: '123', b: 'xyz', 'foo-bar': '123 ~ xyz-a' }; var signature = FunctionComputeClient.getSignature(ACCOUNT_ID, ACCESS_KEY_SECRET, 'GET', '/hello/world', { date: 'today' }, queries); expect(signature).to.be.ok(); expect(signature).to.contain(`FC ${ACCOUNT_ID}:`); });
it('updateFunction with invalid runtime should fail', async function () { try { await client.updateFunction(serviceName, functionName, { description: 'updated function desc', runtime: 10 }); } catch (ex) { expect(ex.stack).to.contain('FCInvalidArgumentError'); expect(ex.stack).to.contain('Runtime is set to an invalid value'); } try { await client.updateFunction(serviceName, initFunctionName, { description: 'updated function desc', runtime: 10 }); } catch (ex) { expect(ex.stack).to.contain('FCInvalidArgumentError'); expect(ex.stack).to.contain('Runtime is set to an invalid value'); } });
it('detect runtime error', function (done) { var tpl = '{{x}}\n \n \n \n \n {{x.y.z}}'; var count = 0; try { new XTemplate(tpl, { name: 'x.xtpl', strict: true, catchError: true }).render({x: 1}); } catch (e) { if (navigator.userAgent.indexOf('Chrome') !== -1) { expect(e.message).to.contain("x.xtpl at line 6"); } expect(e.xtpl).to.eql({ pos: {line: 6}, name: "x.xtpl" }); callback(); } function callback() { ++count; if (count === 1) { done(); } } });
it('.all', async function() { const posts = await Post.all; expect(posts.length).to.be(3); expect(posts.map(post => post.title)).to.contain('New Post'); });