Best JavaScript code snippet using wpt
validate_schema.test.js
Source:validate_schema.test.js
1import config from 'config';2import Joi from 'joi';3import httpStatus from './../../../utils/http_status';4import { validateSchema } from './../../../server/middlewares';5const SCHEMA_TYPES = config.get('SCHEMA_TYPES');6describe('Server Middlewares - Validate Schema', () => {7 let req;8 let res;9 let next;10 let schema;11 beforeEach(() => {12 schema = Joi.object().keys({ key: Joi.string().valid('value') });13 req = { body: { key: 'value' }, query: { key: 'value' } };14 res = { send: jest.fn(), status: jest.fn() };15 next = jest.fn();16 });17 it('calls next if body schema is valid', () => {18 validateSchema(schema, '', SCHEMA_TYPES.TYPE_BODY)(req, res, next);19 expect(next).toHaveBeenCalledTimes(1);20 req.body = undefined;21 validateSchema(schema, '', SCHEMA_TYPES.TYPE_BODY)(req, res, next);22 expect(next).toHaveBeenCalledTimes(2);23 });24 it('fails if body schema is not valid', () => {25 req.body = { key: 'invalid' };26 validateSchema(schema, '', SCHEMA_TYPES.TYPE_BODY)(req, res, next);27 expect(res.status).toHaveBeenCalledTimes(1);28 expect(res.status.mock.calls[0][0]).toBe(httpStatus.BAD_REQUEST);29 expect(res.send).toHaveBeenCalledTimes(1);30 expect(res.send.mock.calls[0][0]).toHaveProperty('error');31 req.body = 10;32 validateSchema(schema, '', SCHEMA_TYPES.TYPE_BODY)(req, res, next);33 expect(res.status).toHaveBeenCalledTimes(2);34 expect(res.status.mock.calls[0][0]).toBe(httpStatus.BAD_REQUEST);35 expect(res.send).toHaveBeenCalledTimes(2);36 expect(res.send.mock.calls[0][0]).toHaveProperty('error');37 });38 it('calls next if query schema is valid', () => {39 validateSchema(schema, '', SCHEMA_TYPES.TYPE_QUERY)(req, res, next);40 expect(next).toHaveBeenCalledTimes(1);41 req.query = undefined;42 validateSchema(schema, '', SCHEMA_TYPES.TYPE_QUERY)(req, res, next);43 expect(next).toHaveBeenCalledTimes(2);44 });45 it('fails if query schema is not valid', () => {46 req.query = { key: 'invalid' };47 validateSchema(schema, '', SCHEMA_TYPES.TYPE_QUERY)(req, res, next);48 expect(res.status).toHaveBeenCalledTimes(1);49 expect(res.status.mock.calls[0][0]).toBe(httpStatus.BAD_REQUEST);50 expect(res.send).toHaveBeenCalledTimes(1);51 expect(res.send.mock.calls[0][0]).toHaveProperty('error');52 req.query = 10;53 validateSchema(schema, '', SCHEMA_TYPES.TYPE_QUERY)(req, res, next);54 expect(res.status).toHaveBeenCalledTimes(2);55 expect(res.status.mock.calls[0][0]).toBe(httpStatus.BAD_REQUEST);56 expect(res.send).toHaveBeenCalledTimes(2);57 expect(res.send.mock.calls[0][0]).toHaveProperty('error');58 });...
projects.js
Source:projects.js
...28 // max_length = dom_text.length;29 // dom_length = 100;30 // setTimeout(type_body,500);31}32function type_body()33{34 dom_length = (dom_length + 1) % max_length; 35 document.querySelector("#bg-body").innerText = dom_text.substr(0,dom_length);36 setTimeout(type_body,20);37}38typewriter_body();...
array.ts
Source:array.ts
1namespace $ {2 const err = $mol_view_tree2_error_str3 /*4 * ```tree5 * prop /6 * \test7 * <= Some $zzz_class8 * ```9 */10 export function $mol_view_tree2_ts_array(11 this: $,12 operator: $mol_tree2,13 context: $mol_view_tree2_context,14 super_method?: $mol_view_tree2_prop | undefined15 ) {16 if (operator.type[0] !== '/') return this.$mol_fail(17 err`Need a \`/\` at ${operator.span}`18 )19 const type_str = operator.type.substring(1)20 const type_body = [21 operator.data('] as '),22 ]23 if (type_str === '') {24 type_body.push(operator.data('readonly any[]'))25 } else if (type_str === 'const') {26 type_body.push(operator.data('const'))27 } else {28 const type = $mol_tree2.data(type_str, [], operator.span.slice(1, type_str.length))29 const is_array = type.value.indexOf('[') !== -130 type_body.push(operator.data('readonly '))31 if (is_array) type_body.push(operator.data('('))32 type_body.push(type)33 if (is_array) type_body.push(operator.data(')'))34 type_body.push(operator.data('[]'))35 }36 const body = this.$mol_view_tree2_ts_array_body(operator, context, super_method)37 return [38 operator.data('['),39 body,40 operator.struct('line', type_body)41 ]42 }...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest(url, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10});
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var page = wptools.page('Barack Obama');4page.get(function(err, resp) {5 var type = page.type_body();6 console.log(type);7 fs.writeFile("type.txt", type, function(err) {8 if (err) {9 return console.log(err);10 }11 console.log("The file was saved!");12 });13});
Using AI Code Generation
1var wptools = require('wptools');2wptools.type_body('Barack Obama', function(err, resp) {3 if (!err) {4 console.log(resp);5 }6});7### wptools.page(name, [options], [callback])8### wptools.category(name, [options], [callback])9### wptools.type(name, [options], [callback])10### wptools.search(name, [options], [callback])11### wptools.get(name, [options], [callback])12### wptools.type_body(name, [options], [callback])
Using AI Code Generation
1var wpt = require('./wpt');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8wpt.type_body(url, body, callback)9var wpt = require('./wpt');10 if (err) {11 console.log(err);12 } else {13 console.log(data);14 }15});16wpt.get_test(test_id, callback)17var wpt = require('./wpt');18wpt.get_test('11111111_1111_1111_1111_111111111111', function (err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25wpt.run_test(url, options, callback)26* `options` - An object containing the options for the test. See the [WebPagetest API](http
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest(options);5wpt.getLocations(function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});9 if (err) return console.error(err);10 console.log(data);11});12}, function(err, data) {13 if (err) return console.error(err);14 console.log(data);15});16wpt.getTestStatus('140227_8T_8e7c7f6e0c6d3b6f3d6f3d6f3d6f3d1', function(err, data) {17 if (err) return console.error(err);18 console.log(data);19});20wpt.getTestResults('140227_8T_8e7c7f6e0c6d3b6f3d6f3d6f3d6f3d1', function(err, data) {21 if (err) return console.error(err);22 console.log(data);23});24wpt.getTestResults('140227_8T_8e7c7f6e0c6d3b6f3d6f3d6f3d6f3d1', {25}, function(err, data) {26 if (err) return console.error(err);27 console.log(data);28});29wpt.getTestResults('140227_8T_8e7c7f6e0c6d3b6f3d6f3d6f3d6f3d1', {30}, function(err, data) {31 if (err)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!