Best JavaScript code snippet using chai
plugins-test.js
Source: plugins-test.js
1module('tAMD/plugins', {2 setup: function() {3 var that = this;4 stop();5 reinitialize().then(function() {6 that.load = function(resource, require, load) {7 require([resource], function(res) {8 res.myPlugin = true;9 load(res);10 });11 };12 define('myPlugin', { load: that.load });13 that.obj = {};14 define('obj', that.obj);15 start();16 });17 },18 teardown: function() {}19});20asyncTest('loads a resource via a plugin', 2, function() {21 require(['myPlugin!obj'], function(res) {22 ok(res, 'loaded myPlugin!obj');23 strictEqual(res.myPlugin, true, 'resource has a "myPlugin" property');24 start();25 });26});27test('supports requiring plugin resource synchronously', 1, function() {28 require(['myPlugin!obj'], function(res) {29 ok(res, 'loaded myPlugin!obj synchronously');30 });31});32test('supports requiring plugin resource via sync require', 1, function() {33 require(['require'], function(require) {34 var res = require('myPlugin!obj');35 ok(res, 'loaded myPlugin!obj via sync require');36 });37});38test('normalizes plugin id', 2, function() {39 define('a/plugin', { load: this.load });40 define('a/resource', ['./plugin!obj'], function(res) {41 ok(res, 'loaded ./plugin!obj');42 });43 define('b/resource', ['../a/plugin!obj'], function(res) {44 ok(res, 'loaded ../a/plugin!obj');45 });46});47test('normalizes resource id', 2, function() {48 define('a/obj', this.obj);49 define('a/test', ['myPlugin!./obj'], function(res) {50 ok(res, 'loaded myPlugin!./obj');51 });52 define('b/test', ['myPlugin!../a/obj'], function(res) {53 ok(res, 'loaded myPlugin!../a/obj');54 });55});56test('supports custom resource id normalization', 1, function() {57 var that = this;58 define('anotherPlugin', {59 load: this.load,60 normalize: function(resourceId) {61 return resourceId.toLowerCase();62 }63 });64 require(['anotherPlugin!OBJ'], function(res) {65 strictEqual(res, that.obj, 'loaded anotherPlugin!OBJ');66 });67});68test('combines custom and standard resource id normalization', 2, function() {69 var that = this;70 define('anotherPlugin', {71 load: this.load,72 normalize: function(resourceId, normalize) {73 return normalize(resourceId.toLowerCase());74 }75 });76 define('a/obj', this.obj);77 define('a/test', ['anotherPlugin!./OBJ'], function(res) {78 strictEqual(res, that.obj, 'loaded anotherPlugin!./OBJ');79 });80 define('b/test', ['anotherPlugin!../a/OBJ'], function(res) {81 strictEqual(res, that.obj, 'loaded anotherPlugin!../a/OBJ');82 });83});84asyncTest('supports asynchronous plugin lookup', 1, function() {85 var that = this;86 require(['asyncPlugin!__obj__'], function(res) {87 strictEqual(res, that.obj, 'asynchronously normalized resource id');88 start();89 });90 setTimeout(function() {91 define('asyncPlugin', {92 load: that.load,93 normalize: function(resourceId) {94 return resourceId.replace(/_/g, '');95 }96 });97 }, 100);98});99test('supports plugin chains', 4, function() {100 var that = this;101 define('a/test', ['foo!bar!nao!obj'], function(res) {102 strictEqual(res, that.obj, 'loaded resource through three plugins');103 strictEqual(res.foo, true, 'resource gets a "foo" attribute');104 strictEqual(res.bar, true, 'resource gets a "bar" attribute');105 strictEqual(res.nao, true, 'resource gets a "nao" attribute');106 });107 define('foo', { load: loader('foo') });108 define('bar', { load: loader('bar') });109 define('nao', { load: loader('nao') });110 function loader(label) {111 return function(resourceId, require, load) {112 require([resourceId], function(res) {113 res[label] = true;114 load(res);115 });116 };117 }118});119// TODO: Is this how chained plugins with relative ids should be120// handled?121//test('supports plugin chains with relative plugin ids', 4, function() {122// var that = this;123//124// define('a/test', ['foo!./bar!../b/nao!./obj'], function(res) {125// strictEqual(res, that.obj, 'loaded resource through three plugins');126// strictEqual(res.foo, true, 'resource gets a "foo" attribute');127// strictEqual(res.bar, true, 'resource gets a "bar" attribute');128// strictEqual(res.nao, true, 'resource gets a "nao" attribute');129// });130//131// define('foo', { load: loader('foo') });132// define('a/bar', { load: loader('bar') });133// define('b/nao', { load: loader('nao') });134//135// function loader(label) {136// return function(resourceId, require, load) {137// require([resourceId], function(res) {138// res[label] = true;139// load(res);140// });141// };142// }...
topmark.test.js
Source: topmark.test.js
1/* eslint-disable func-names */2import chai from 'chai';3import Topmark from '../src/lib/topmark';4chai.should();5describe('Topmark', () => {6 describe('constructor', () => {7 const goodOptions = {8 default: {9 option: true,10 },11 pluginSlug: {12 option: false,13 },14 };15 const topmark = new Topmark(goodOptions);16 it('should accept an options object', () => {17 topmark.options.default.option.should.equal(true);18 });19 it('should merge plugin options with default options', () => {20 topmark.getOptions('pluginSlug').option.should.equal(false);21 });22 it('should return default options if no pluginSlug options are defined', () => {23 topmark.getOptions('unsetPluginSlug').option.should.equal(true);24 });25 });26 describe('registerPlugins', () => {27 it('should register a single plugin from a string', (done) => {28 const topmark = new Topmark();29 topmark.register('another-plugin').then(() => {30 topmark.registrations.anotherPlugin.name.should.equal('anotherPlugin');31 done();32 }).catch(() => done());33 });34 it('should reject anything other than a plugin string or array of plugin strings', (done) => {35 const topmark = new Topmark();36 topmark.register({ plugin: 'this is not a plugin' }).then(() => {37 done();38 }).catch((err) => {39 err.should.equal('Must be a plugin string, or an array of plugin strings');40 done();41 });42 });43 it('Load a plugin from npm', function (done) {44 this.timeout(50000);45 const topmark = new Topmark();46 const packageName = 'topmark-loadspeed';47 // eslint-disable-next-line global-require48 const pluginSlug = require(packageName).attributes.name;49 topmark.register(packageName).then(() => {50 topmark.registrations[pluginSlug].should.not.equal(undefined);51 done();52 }).catch(() => done());53 });54 describe('multiple plugins', () => {55 const options = {56 default: {57 thing: 1,58 default: true,59 },60 anotherPlugin: {61 thing: 2,62 default: false,63 },64 simplePlugin: {65 thing: 3,66 },67 };68 it('should register multiple plugins from an array of strings', (done) => {69 const topmark = new Topmark(options);70 topmark.register([71 'simple-plugin',72 'another-plugin',73 ]).then(() => {74 topmark.registrations.anotherPlugin.options.thing75 .should.equal(options.anotherPlugin.thing);76 topmark.registrations.simplePlugin.options.thing.should.equal(options.simplePlugin.thing);77 topmark.registrations.simplePlugin.name.should.equal('simplePlugin');78 topmark.registrations.anotherPlugin.name.should.equal('anotherPlugin');79 done();80 }).catch(() => done());81 });82 });83 });84 describe('reporting', () => {85 it('should help plugins add reporting data', (done) => {86 const options = {87 simplePlugin: {88 url: 'http://google.com',89 },90 };91 const topmark = new Topmark(options);92 topmark.register('simple-plugin').then(() => {93 topmark.results[0].plugin.should.equal('simplePlugin');94 topmark.results[0].url.should.equal('http://google.com');95 done();96 }).catch(() => done());97 });98 });...
lint-test.js
Source: lint-test.js
1import sinon from 'sinon'2import lint from '../index'3describe('Linting styles', () => {4 it('should execute every plugin', () => {5 const plugin = sinon.spy()6 const anotherPlugin = sinon.spy()7 lint({ plugins: [plugin, anotherPlugin] })({ color: 'red' })8 expect(plugin.calledOnce).toBe(true)9 expect(anotherPlugin.calledOnce).toBe(true)10 })11 it('should add warnings', () => {12 const plugin = ({ style, addWarning }) => {13 if (style.foo) {14 addWarning({ description: 'foobar' })15 }16 }17 const warnings = lint({ plugins: [plugin] })({18 color: 'red',19 foo: true,20 })21 expect(warnings.length).toBe(1)22 expect(warnings[0]).toEqual({ description: 'foobar' })23 })...
Using AI Code Generation
1let response = await contract.submitTransaction('anotherPlugin', 'arg1', 'arg2');2let response = await contract.submitTransaction('anotherPlugin', 'arg1', 'arg2');3const { BasePlugin } = require('@theledger/fabric-chaincode-utils');4class MyPlugin extends BasePlugin {5}6const { BasePlugin } = require('@theledger/fabric-chaincode-utils');7class MyPlugin extends BasePlugin {8 async init(stub, args) {9 }10}11const { BasePlugin } = require('@theledger/fabric-chaincode-utils');12class MyPlugin extends BasePlugin {13 async init(stub, args) {14 }15 async invoke(stub, args) {16 }17}18const { BasePlugin } = require('@theledger/fabric-chaincode-utils');19class MyPlugin extends BasePlugin {20 async init(stub, args) {21 }22 async invoke(stub, args) {23 }24}25module.exports = MyPlugin;26const shim = require('fabric-shim');27const Chaincode = require('@theledger/fabric-chaincode-utils');28const MyPlugin = require('./myPlugin');29const chaincode = new Chaincode();30chaincode.registerPlugin('myPlugin', new MyPlugin());
Using AI Code Generation
1chainPlugin.anotherPlugin.method();2chainPlugin.method();3chainPlugin.anotherPlugin.anotherPlugin.method();4chainPlugin.anotherPlugin.method();5chainPlugin.anotherPlugin.method();6chainPlugin.method();7chainPlugin.anotherPlugin.anotherPlugin.method();8chainPlugin.anotherPlugin.method();9chainPlugin.anotherPlugin.method();10chainPlugin.method();11chainPlugin.anotherPlugin.anotherPlugin.method();12chainPlugin.anotherPlugin.method();13chainPlugin.anotherPlugin.method();14chainPlugin.method();15chainPlugin.anotherPlugin.anotherPlugin.method();16chainPlugin.anotherPlugin.method();17chainPlugin.anotherPlugin.method();18chainPlugin.method();19chainPlugin.anotherPlugin.anotherPlugin.method();20chainPlugin.anotherPlugin.method();21chainPlugin.anotherPlugin.method();22chainPlugin.method();23chainPlugin.anotherPlugin.anotherPlugin.method();24chainPlugin.anotherPlugin.method();25chainPlugin.anotherPlugin.method();26chainPlugin.method();27chainPlugin.anotherPlugin.anotherPlugin.method();28chainPlugin.anotherPlugin.method();
Using AI Code Generation
1var anotherPlugin = require('anotherPlugin');2anotherPlugin.anotherPluginMethod();3var anotherPlugin = require('anotherPlugin');4anotherPlugin.anotherPluginMethod();5var anotherPlugin = {6 anotherPluginMethod: function() {7 }8};9module.exports = anotherPlugin;
Using AI Code Generation
1var chain = require('chain');2chain.anotherPlugin.method();3module.exports = {4 method: function() {5 console.log('anotherPlugin method of chain');6 }7};8module.exports = {9 method: function() {10 console.log('method of chain');11 }12};13var chain = require('chain');14chain.anotherPlugin.method();15module.exports = {16 method: function() {17 console.log('anotherPlugin method of chain');18 }19};20module.exports = {21 method: function() {22 console.log('method of chain');23 }24};25var chain = require('chain');26chain.anotherPlugin.method();27module.exports = {28 method: function() {29 console.log('anotherPlugin method of chain');30 }31};32module.exports = {33 method: function() {34 console.log('method of chain');35 }36};37var chain = require('chain');38chain.anotherPlugin.method();39module.exports = {40 method: function() {41 console.log('anotherPlugin method of chain');42 }43};44module.exports = {45 method: function() {46 console.log('method of chain');47 }48};49var chain = require('chain');50chain.anotherPlugin.method();51module.exports = {52 method: function() {53 console.log('anotherPlugin method of chain');54 }55};56module.exports = {57 method: function() {58 console.log('method of chain');59 }60};
Check out the latest blogs from LambdaTest on this topic:
Nowadays, every organization wants an extra edge over its competitors. Be it launching a product faster or delivering a higher quality product, they always want to outperform others. To ensure faster got-to-market with a high-quality web application, organizations utilize Selenium test automation in order to automate their test efforts. Enabling them to execute tests faster, with fewer mistakes in a scalable manner. Test automation has certainly made the testing process much faster, but what if I told you that your release can get even faster!
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium Python Tutorial and Selenium pytest Tutorial.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium JavaScript Tutorial.
Digital business transformation is a race against time. A company’s survival directly depends on its transformation speed with continuous pressure to reinvent itself in short cycles. In such a competitive ecosystem, only first movers can gain a competitive advantage.
CSS is one of the fundamental pillars in web development and design. While CSS started as something that can change the style of a web page, every CSS specification iteration now brings more to the table, precisely when it comes to cross browser compatibility.
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!!