Best JavaScript code snippet using wpt
metadata_edit_spec.js
Source:metadata_edit_spec.js
...150 const verifyEntry = function(index, display_name, type) {151 expect(childModels[index].get('display_name')).toBe(display_name);152 verifyInputType(childViews[index], type);153 };154 verifyEntry(0, 'Display Name', 'text');155 verifyEntry(1, 'Inputs', 'number');156 verifyEntry(2, 'List', '');157 verifyEntry(3, 'New Dict', '');158 verifyEntry(4, 'Show Answer', 'select-one');159 verifyEntry(5, 'Time', 'text');160 verifyEntry(6, 'Unknown', 'text');161 verifyEntry(7, 'Weight', 'number');162 });163 it("returns its display name", function() {164 const view = new MetadataView.Editor({collection: this.model});165 expect(view.getDisplayName()).toBe("Word cloud");166 });167 it("returns an empty string if there is no display name property with a valid value", function() {168 let view = new MetadataView.Editor({collection: new MetadataCollection()});169 expect(view.getDisplayName()).toBe("");170 view = new MetadataView.Editor({collection: new MetadataCollection([171 {172 default_value: null,173 display_name: "Display Name",174 explicitly_set: false,175 field_name: "display_name",...
index.js
Source:index.js
...43 const entry = await strapi44 .query("suggestion")45 .findOne({ id: data.body.id });46 // verify from database47 verifyEntry(entry);48 // verify the response49 verifyEntry(data.body);50 });51 });52 describe("/suggestions/<id>/like", () => {53 it("should increase like_count and return the updated entry", async () => {54 // create a suggestion55 const suggestion = await strapi.services.suggestion.create({56 title: "title",57 content: "content",58 author: "author",59 });60 const data = await request(strapi.server)61 .post(`/suggestions/${suggestion.id}/like`)62 .set("Content-Type", "application/json")63 .send({64 user: "user1",65 })66 .expect(200);67 const verifyEntry = (entry, id) => {68 expect(entry.id).toEqual(id);69 expect(entry.like_count).toEqual(1);70 };71 const entry = await strapi72 .query("suggestion")73 .findOne({ id: suggestion.id });74 // verify from database75 verifyEntry(entry, suggestion.id);76 // veridy the response77 verifyEntry(data.body, suggestion.id);78 });79 it("should not allow multiple likes to same suggestion from one user", async () => {80 // create a suggestion81 const suggestion = await strapi.services.suggestion.create({82 title: "title",83 content: "content",84 author: "author",85 });86 await request(strapi.server)87 .post(`/suggestions/${suggestion.id}/like`)88 .set("Content-Type", "application/json")89 .send({90 user: "user1",91 })92 .expect(200)93 .then((data) => {94 expect(data.body.id).toEqual(suggestion.id);95 expect(data.body.like_count).toEqual(1);96 });97 await request(strapi.server)98 .post(`/suggestions/${suggestion.id}/like`)99 .set("Content-Type", "application/json")100 .send({101 user: "user1",102 })103 .expect(400)104 .then((data) => {105 expect(data.text).toEqual("already liked");106 });107 });108 it("should return 404 when liking nonexistent suggestion", async () => {109 // Create a comment to that suggesion110 await request(strapi.server)111 .post(`/suggestions/99/like`)112 .set("Content-Type", "application/json")113 .send({114 user: "test",115 })116 .expect(404);117 });118 });119 describe("/suggestions/<id>/unlike", () => {120 it("should decrease like_count and return the updated entry", async () => {121 // create a suggestion122 const suggestion = await strapi.services.suggestion.create({123 title: "title",124 content: "content",125 author: "author",126 });127 const verifyEntry = (entry, id, likeCount) => {128 expect(entry.id).toEqual(id);129 expect(entry.like_count).toEqual(likeCount);130 };131 const response1 = await request(strapi.server)132 .post(`/suggestions/${suggestion.id}/like`)133 .set("Content-Type", "application/json")134 .send({135 user: "user1",136 })137 .expect(200);138 // Verify that the like was added139 const entry1 = await strapi140 .query("suggestion")141 .findOne({ id: suggestion.id });142 // verify from database143 verifyEntry(entry1, suggestion.id, 1);144 // verify the response145 verifyEntry(response1.body, suggestion.id, 1);146 const response2 = await request(strapi.server)147 .post(`/suggestions/${suggestion.id}/unlike`)148 .set("Content-Type", "application/json")149 .send({150 user: "user1",151 })152 .expect(200);153 // Verify that the like was removed154 const entry2 = await strapi155 .query("suggestion")156 .findOne({ id: suggestion.id });157 // verify from database158 verifyEntry(entry2, suggestion.id, 0);159 // verify the response160 verifyEntry(response2.body, suggestion.id, 0);161 });162 it("should not allow unliking of a not liked suggestion", async () => {163 // create a suggestion164 const suggestion = await strapi.services.suggestion.create({165 title: "title",166 content: "content",167 author: "author",168 });169 await request(strapi.server)170 .post(`/suggestions/${suggestion.id}/unlike`)171 .set("Content-Type", "application/json")172 .send({173 user: "user1",174 })...
worker-performance.worker.js
Source:worker-performance.worker.js
...23}, "Can use performance.measure in workers");24test(function testPerformanceGetEntriesByName () {25 var mark1s = performance.getEntriesByName("mark1");26 assert_equals(mark1s.length, 1, "getEntriesByName gave correct number of entries");27 verifyEntry(mark1s[0], "mark1", "mark", 0, "Entry got by name");28}, "Can use performance.getEntriesByName in workers");29var marks;30var measures;31test(function testPerformanceGetEntriesByType () {32 marks = performance.getEntriesByType("mark");33 assert_equals(marks.length, 2, "getEntriesByType gave correct number of entries");34 verifyEntry(marks[0], "mark1", "mark", 0, "First mark entry");35 verifyEntry(marks[1], "mark2", "mark", 0, "Second mark entry");36 measures = performance.getEntriesByType("measure");37 assert_equals(measures.length, 1, "getEntriesByType(\"measure\") gave correct number of entries");38 verifyEntry(measures[0], "measure1", "measure", marks[1].startTime - marks[0].startTime, "Measure entry");39}, "Can use performance.getEntriesByType in workers");40test(function testPerformanceEntryOrder () {41 assert_greater_than(marks[0].startTime, start, "First mark startTime is after a time before it");42 assert_greater_than(marks[1].startTime, marks[0].startTime, "Second mark startTime is after first mark startTime");43 assert_equals(measures[0].startTime, marks[0].startTime, "measure's startTime is the first mark's startTime");44}, "Performance marks and measures seem to be working correctly in workers");45test(function testPerformanceClearing () {46 performance.clearMarks();47 assert_equals(performance.getEntriesByType("mark").length, 0, "clearMarks cleared the marks");48 performance.clearMeasures();49 assert_equals(performance.getEntriesByType("measure").length, 0, "clearMeasures cleared the measures");50}, "Can use clearMarks and clearMeasures in workers");51test(function testPerformanceResourceTiming () { // Resource timing52 var start = performance.now();...
Using AI Code Generation
1var wpt = require('./wpt.js');2wpt.verifyEntry("test", "test", function (err, res) {3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Result: ' + res);7 }8});9var wpt = require('webpagetest');10var webpagetest = new wpt('API_KEY');11module.exports = {12 verifyEntry: function (url, location, callback) {13 webpagetest.runTest(url, {14 }, function (err, data) {15 if (err) {16 callback(err);17 } else {18 callback(null, data);19 }20 });21 }22};
Using AI Code Generation
1var wpt = require('./wpt.js');2 if(err){3 console.log(err);4 } else {5 console.log(data);6 }7});8module.exports = {9 verifyEntry: function(url, title, description, callback){10 callback(null, 'entry verified');11 }12};13module.exports = {14 verifyEntry: function(url, title, description, callback){15 callback(null, 'entry verified');16 }17};18module.exports = {19 verifyEntry: function(url, title, description, callback){20 callback('error');21 }22};23var wpt = require('./wpt.js');24 if(err){25 console.log(err);26 } else {27 console.log(data);28 }29});30module.exports = {31 verifyEntry: function(url, title, description, callback){32 callback('error');33 }34};35var wpt = require('./wpt.js');36 if(err){37 console.log(err);38 } else {39 console.log(data);40 }41});42module.exports = {43 verifyEntry: function(url, title, description, callback){44 callback('error');45 }46};
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3wpt.verifyEntry('ENTRY_ID', function(err, data) {4 if(err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('wpt');11var wpt = new wpt('API_KEY');12wpt.getLocations(function(err, data) {13 if(err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('wpt');20var wpt = new wpt('API_KEY');21wpt.getTests(function(err, data) {22 if(err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('wpt');29var wpt = new wpt('API_KEY');30wpt.getTest('TEST_ID', function(err, data) {31 if(err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wpt = require('wpt');38var wpt = new wpt('API_KEY');39wpt.getTestResults('TEST_ID', function(err, data) {40 if(err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wpt = require('wpt');47var wpt = new wpt('API_KEY');48wpt.getTestStatus('TEST_ID', function(err, data) {49 if(err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wpt = require('wpt');56var wpt = new wpt('API_KEY');57wpt.getTestRequests('TEST_ID', function(err, data) {58 if(err) {59 console.log(err
Using AI Code Generation
1var wpt = new Wpt();2var entry = new Entry();3entry = wpt.loadEntry("testEntry.json");4wpt.verifyEntry(entry);5var wpt = new Wpt();6var entry = new Entry();7entry = wpt.loadEntry("testEntry.json");8wpt.verifyEntry(entry);9var wpt = new Wpt();10var entry = new Entry();11entry = wpt.loadEntry("testEntry.json");12wpt.verifyEntry(entry);13var wpt = new Wpt();14var entry = new Entry();15entry = wpt.loadEntry("testEntry.json");16wpt.verifyEntry(entry);17var wpt = new Wpt();18var entry = new Entry();19entry = wpt.loadEntry("testEntry.json");20wpt.verifyEntry(entry);21var wpt = new Wpt();22var entry = new Entry();23entry = wpt.loadEntry("testEntry.json");24wpt.verifyEntry(entry);25var wpt = new Wpt();26var entry = new Entry();
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!!