Best JavaScript code snippet using best
kernelspec.spec.ts
Source:kernelspec.spec.ts
...13afterAll(async () => {14 await server.shutdown();15});16describe('kernel', () => {17 describe('KernelSpec.getSpecs()', () => {18 it('should load the kernelspecs', async () => {19 const specs = await KernelSpecAPI.getSpecs();20 expect(specs.default).toBeTruthy();21 });22 it('should accept ajax options', async () => {23 const serverSettings = makeSettings();24 const specs = await KernelSpecAPI.getSpecs(serverSettings);25 expect(specs.default).toBeTruthy();26 });27 it('should handle a missing default parameter', async () => {28 const serverSettings = getRequestHandler(200, {29 kernelspecs: { python: PYTHON_SPEC }30 });31 const specs = await KernelSpecAPI.getSpecs(serverSettings);32 expect(specs.default).toBeTruthy();33 });34 it('should throw for a missing kernelspecs parameter', async () => {35 const serverSettings = getRequestHandler(200, {36 default: PYTHON_SPEC.name37 });38 const promise = KernelSpecAPI.getSpecs(serverSettings);39 await expect(promise).rejects.toThrow(/No kernelspecs found/);40 });41 it('should omit an invalid kernelspec', async () => {42 const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));43 R_SPEC.name = 1;44 const serverSettings = getRequestHandler(200, {45 default: 'python',46 kernelspecs: {47 R: R_SPEC,48 python: PYTHON_SPEC49 }50 });51 const specs = await KernelSpecAPI.getSpecs(serverSettings);52 expect(specs.default).toBe('python');53 expect(specs.kernelspecs['R']).toBeUndefined();54 });55 it('should handle an improper name', async () => {56 const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));57 R_SPEC.name = 1;58 const serverSettings = getRequestHandler(200, {59 default: 'R',60 kernelspecs: { R: R_SPEC }61 });62 const promise = KernelSpecAPI.getSpecs(serverSettings);63 await expect(promise).rejects.toThrow(/No valid kernelspecs found/);64 });65 it('should handle an improper language', async () => {66 const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));67 R_SPEC.spec.language = 1;68 const serverSettings = getRequestHandler(200, {69 default: 'R',70 kernelspecs: { R: R_SPEC }71 });72 const promise = KernelSpecAPI.getSpecs(serverSettings);73 await expect(promise).rejects.toThrow(/No valid kernelspecs found/);74 });75 it('should handle an improper argv', async () => {76 const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));77 R_SPEC.spec.argv = 'hello';78 const serverSettings = getRequestHandler(200, {79 default: 'R',80 kernelspecs: { R: R_SPEC }81 });82 const promise = KernelSpecAPI.getSpecs(serverSettings);83 await expect(promise).rejects.toThrow(/No valid kernelspecs found/);84 });85 it('should handle an improper display_name', async () => {86 const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));87 R_SPEC.spec.display_name = ['hello'];88 const serverSettings = getRequestHandler(200, {89 default: 'R',90 kernelspecs: { R: R_SPEC }91 });92 const promise = KernelSpecAPI.getSpecs(serverSettings);93 await expect(promise).rejects.toThrow(/No valid kernelspecs found/);94 });95 it('should handle missing resources', async () => {96 const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));97 delete R_SPEC.resources;98 const serverSettings = getRequestHandler(200, {99 default: 'R',100 kernelspecs: { R: R_SPEC }101 });102 const promise = KernelSpecAPI.getSpecs(serverSettings);103 await expect(promise).rejects.toThrow(/No valid kernelspecs found/);104 });105 it('should throw an error for an invalid response', async () => {106 const serverSettings = getRequestHandler(201, {});107 const promise = KernelSpecAPI.getSpecs(serverSettings);108 await expect(promise).rejects.toThrow(/Invalid response: 201 Created/);109 });110 it('should handle metadata', async () => {111 const PYTHON_SPEC_W_MD = JSON.parse(JSON.stringify(PYTHON_SPEC));112 // eslint-disable-next-line camelcase113 PYTHON_SPEC_W_MD.spec.metadata = { some_application: { key: 'value' } };114 const serverSettings = getRequestHandler(200, {115 default: 'python',116 kernelspecs: { python: PYTHON_SPEC_W_MD }117 });118 const specs = await KernelSpecAPI.getSpecs(serverSettings);119 expect(specs.kernelspecs['python']).toHaveProperty('metadata');120 const metadata = specs.kernelspecs['python']!.metadata;121 expect(metadata).toHaveProperty('some_application');122 expect((metadata as any).some_application).toHaveProperty('key', 'value');123 });124 it('should handle env values', async () => {125 const PYTHON_SPEC_W_ENV = JSON.parse(JSON.stringify(PYTHON_SPEC));126 PYTHON_SPEC_W_ENV.spec.env = {127 SOME_ENV: 'some_value',128 LANG: 'en_US.UTF-8'129 };130 const serverSettings = getRequestHandler(200, {131 default: 'python',132 kernelspecs: { python: PYTHON_SPEC_W_ENV }133 });134 const specs = await KernelSpecAPI.getSpecs(serverSettings);135 expect(specs.kernelspecs['python']).toHaveProperty('env');136 const env = specs.kernelspecs['python']!.env;137 expect(env).toHaveProperty('SOME_ENV', 'some_value');138 expect(env).toHaveProperty('LANG', 'en_US.UTF-8');139 });140 });...
ids-device-env-specs-utils-func-test.ts
Source:ids-device-env-specs-utils-func-test.ts
...4import { getSpecs } from '../../src/utils/ids-device-env-specs-utils/ids-device-env-specs-utils';5describe('IdsDeviceEnvUtils Tests', () => {6 let specs: any;7 beforeEach(async () => {8 specs = getSpecs();9 });10 afterEach(async () => {11 specs = null;12 });13 it('should initialize without an errors', () => {14 expect(specs).toBeDefined();15 });16 it('should type check', () => {17 expect(typeof specs.browser).toBe('string');18 expect(typeof specs.browserVersion).toBe('string');19 expect(typeof specs.isMobile).toBe('boolean');20 expect(typeof specs.platform).toBe('string');21 expect(typeof specs.browserLanguage).toBe('string');22 expect(typeof specs.idsVersion).toBe('string');23 });24 it('should check isMobile with matchMedia present', () => {25 expect(specs.isMobile).toBeFalsy();26 Object.defineProperty(window, 'matchMedia', {27 value: jest.fn().mockImplementation((query) => ({28 matches: false,29 media: query30 }))31 });32 specs = getSpecs();33 expect(specs.isMobile).toBeFalsy();34 });35 it('should detect browser and device specs', () => {36 const userAgentGetter = jest.spyOn(window.navigator, 'userAgent', 'get');37 const platformGetter = jest.spyOn(window.navigator, 'platform', 'get');38 const appVersionGetter = jest.spyOn(window.navigator, 'appVersion', 'get');39 const appNameGetter = jest.spyOn(window.navigator, 'appName', 'get');40 userAgentGetter.mockReturnValue('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36');41 appVersionGetter.mockReturnValue('5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36');42 platformGetter.mockReturnValue('MacIntel');43 specs = getSpecs();44 expect(specs.browser).toEqual('Chrome');45 expect(specs.browserVersion).toEqual('92.0.4515.159');46 expect(specs.isMobile).toBeFalsy();47 expect(specs.platform).toEqual('MacIntel');48 expect(specs.browserLanguage).toEqual('en-US');49 userAgentGetter.mockReturnValue('Mozilla/5.0 iPad OS 10 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15');50 appVersionGetter.mockReturnValue('5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15');51 platformGetter.mockReturnValue('MacIntel');52 specs = getSpecs();53 expect(specs.browser).toEqual('Safari');54 expect(specs.browserVersion).toEqual('14.1');55 expect(specs.platform).toEqual('MacIntel');56 expect(specs.browserLanguage).toEqual('en-US');57 userAgentGetter.mockReturnValue('Mozilla/5.0 Android 10.5.2 Firefox/92.0.4515.159');58 specs = getSpecs();59 expect(specs.browser).toEqual('Firefox');60 expect(specs.browserVersion).toEqual('92.0.4515.159');61 userAgentGetter.mockReturnValue('Mozilla/5.0 Windows 10.0 Opera 92 OPR 92');62 specs = getSpecs();63 expect(specs.browser).toEqual('Opera');64 expect(specs.browserVersion).toEqual('92');65 userAgentGetter.mockReturnValue('Mozilla/5.0 Windows 10.0 Edg 4');66 specs = getSpecs();67 expect(specs.browser).toEqual('Microsoft Edge');68 expect(specs.browserVersion).toEqual('4');69 userAgentGetter.mockReturnValue('Mozilla/5.0 Windows 8.0 MSIE 11)');70 specs = getSpecs();71 expect(specs.browser).toEqual('Microsoft Internet Explorer');72 expect(specs.browserVersion).toEqual('11');73 userAgentGetter.mockReturnValue('Mozilla/5.0 Windows 8.0 Trident/rv:11.0;');74 specs = getSpecs();75 expect(specs.browser).toEqual('Microsoft Internet Explorer');76 expect(specs.browserVersion).toEqual('11.0');77 userAgentGetter.mockReturnValue('Mozilla/5.0 Windows 10.0 Opera Version 92');78 specs = getSpecs();79 expect(specs.browser).toEqual('Opera');80 expect(specs.browserVersion).toEqual('92');81 userAgentGetter.mockReturnValue('Safari/92');82 specs = getSpecs();83 expect(specs.browser).toEqual('Safari');84 expect(specs.browserVersion).toEqual('92');85 appNameGetter.mockReturnValue('Microsoft Internet Explorer');86 specs = getSpecs();87 expect(specs.browserLanguage).toBe('en-US');88 });...
Using AI Code Generation
1var BestBuy = require('./BestBuy');2var bestBuy = new BestBuy();3bestBuy.getSpecs('samsung', function(err, specs) {4 if (err) {5 console.log(err);6 } else {7 console.log(specs);8 }9});10var request = require('request');11var cheerio = require('cheerio');12var BestBuy = function() {};13BestBuy.prototype.getSpecs = function(model, callback) {14 request(url, function(err, response, body) {15 if (err) {16 return callback(err);17 }18 if (response.statusCode !== 200) {19 return callback(new Error('Unexpected status code: ' + response.statusCode));20 }21 var $ = cheerio.load(body);22 var specs = [];23 $('.sku-item').each(function() {24 var spec = {};25 spec.name = $(this).find('.sku-title a').text();26 spec.price = $(this).find('.priceView-customer-price span').text();27 spec.url = $(this).find('.sku-title a').attr('href');28 specs.push(spec);29 });30 callback(null, specs);31 });32};33module.exports = BestBuy;34[ { name: 'Samsung - 55" Class (54.6" Diag.) - LED - 2160p - Smart - 4K Ultra HD TV with High Dynamic Range',
Using AI Code Generation
1var BestBuy = require('./BestBuy.js');2var bb = new BestBuy();3bb.getSpecs("samsung", function(err, data) {4 if (err) {5 console.log("Error: " + err);6 } else {7 console.log(data);8 }9});10var request = require('request');11var cheerio = require('cheerio');12var BestBuy = function() {13 this.getSpecs = function(searchTerm, callback) {14 request(url, function(err, resp, body) {15 if (err) {16 callback(err);17 } else {18 var $ = cheerio.load(body);19 var result = [];20 var specs = {};21 var specsArray = [];22 $('.list-item').each(function(i, element) {23 var a = $(this);24 var title = a.find('a').attr('title');25 var price = a.find('.priceView-hero-price').text();26 var specs = a.find('.specs-list').text();27 var specsArray = specs.split(" ");28 var specs = {};29 for (var i = 0; i < specsArray.length; i++) {30 var spec = specsArray[i];31 var specArray = spec.split(":");32 specs[specArray[0]] = specArray[1];33 }34 result.push({35 });36 });37 callback(null, result);38 }39 });40 };41};42module.exports = BestBuy;
Using AI Code Generation
1var request = require('request');2request({3}, function (error, response, body) {4 if (!error && response.statusCode === 200) {5 }6})7var request = require('request');8request({9}, function (error, response, body) {10 if (!error && response.statusCode === 200) {11 }12})13var request = require('request');14request({15}, function (error, response, body) {16 if (!error && response.statusCode === 200) {17 }18})19var request = require('request');
Using AI Code Generation
1var bby = require('bestbuy')(process.env.API_KEY);2var url = bby.products('search=ipod', {show: 'sku,name,salePrice', pageSize: 3, page: 2});3bby.getSpecs(url, function(err, data) {4 console.log(data);5});6var bby = require('bestbuy')(process.env.API_KEY);7var url = bby.products('search=ipod', {show: 'sku,name,salePrice', pageSize: 3, page: 2});8bby.getSpecs(url, function(err, data) {9 console.log(data);10});11var bby = require('bestbuy')(process.env.API_KEY);12var url = bby.products('search=ipod', {show: 'sku,name,salePrice', pageSize: 3, page: 2});13bby.getSpecs(url, function(err, data) {14 console.log(data);15});16var bby = require('bestbuy')(process.env.API_KEY);17var url = bby.products('search=ipod', {show: 'sku,name,salePrice', pageSize: 3, page: 2});18bby.getSpecs(url, function(err, data) {19 console.log(data);20});21var bby = require('bestbuy')(process.env.API_KEY);22var url = bby.products('search=ipod', {show: 'sku,name,salePrice', pageSize: 3, page: 2});23bby.getSpecs(url, function(err, data) {24 console.log(data);25});26var bby = require('bestbuy')(process.env.API_KEY);27var url = bby.products('search=ipod', {show: 'sku,name,salePrice', pageSize: 3, page: 2});28bby.getSpecs(url, function(err, data) {29 console.log(data);30});
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!!