How to use normaliseOptions method in chai

Best JavaScript code snippet using chai

config-spec.js

Source:config-spec.js Github

copy

Full Screen

...5const normaliseOptions = require('../lib/config.js');6const DEFAULT_OPTIONS = normaliseOptions.DEFAULT_OPTIONS;7describe('Correctly understands all configuration permutations', () => {8 it('defaults all options if none passed', () => {9 expect(normaliseOptions()).toEqual(DEFAULT_OPTIONS);10 });11 it('defaults all options if null passed', () => {12 expect(normaliseOptions(null)).toEqual(DEFAULT_OPTIONS);13 });14 it('handles single default value', () => {15 const options = { defaultAttribute: 'async' };16 const expected = Object.assign({}, DEFAULT_OPTIONS, options);17 expect(normaliseOptions(options)).toEqual(expected);18 });19 it('handles single String pattern', () => {20 const options = { async: '*.js' };21 const expected = Object.assign({}, DEFAULT_OPTIONS, {22 async: {23 test: ['*.js']24 }25 });26 expect(normaliseOptions(options)).toEqual(expected);27 });28 it('handles single Regex pattern', () => {29 const options = { inline: /\*.js$/ };30 const expected = Object.assign({}, DEFAULT_OPTIONS, {31 inline: {32 test: [/\*.js$/]33 }34 });35 expect(normaliseOptions(options)).toEqual(expected);36 });37 it('handles Array of String and Regex patterns', () => {38 const options = { defer: ['*.js', /\*.js$/] };39 const expected = Object.assign({}, DEFAULT_OPTIONS, {40 defer: {41 test: ['*.js', /\*.js$/]42 }43 });44 expect(normaliseOptions(options)).toEqual(expected);45 });46 it('handles hash configuration with single String for attribute', () => {47 const options = {48 module: {49 test: '*.js'50 }51 };52 const expected = Object.assign({}, DEFAULT_OPTIONS, {53 module: {54 test: ['*.js']55 }56 });57 expect(normaliseOptions(options)).toEqual(expected);58 });59 it('handles full hash configuration for attribute', () => {60 const options = {61 module: {62 test: ['*.js', /\*.js$/]63 }64 };65 const expected = Object.assign({}, DEFAULT_OPTIONS, {66 module: {67 test: ['*.js', /\*.js$/]68 }69 });70 expect(normaliseOptions(options)).toEqual(expected);71 });72 it('handles single Regex pattern for resource hint', () => {73 const options = { preload: /\*.js$/ };74 const expected = Object.assign({}, DEFAULT_OPTIONS, {75 preload: {76 test: [/\*.js$/],77 chunks: 'initial'78 }79 });80 expect(normaliseOptions(options)).toEqual(expected);81 });82 it('handles Array of String and Regex patterns for resource hint', () => {83 const options = { prefetch: ['*.js', /\*.js$/] };84 const expected = Object.assign({}, DEFAULT_OPTIONS, {85 prefetch: {86 test: ['*.js', /\*.js$/],87 chunks: 'initial'88 }89 });90 expect(normaliseOptions(options)).toEqual(expected);91 });92 it('handles partial hash configuration for resource hint', () => {93 const options = {94 preload: {95 test: ['*.js', /\*.js$/]96 }97 };98 const expected = Object.assign({}, DEFAULT_OPTIONS, {99 preload: {100 test: ['*.js', /\*.js$/],101 chunks: 'initial'102 }103 });104 expect(normaliseOptions(options)).toEqual(expected);105 });106 it('handles full hash configuration with single string for resource hint', () => {107 const options = {108 preload: {109 test: '.js',110 chunks: 'all'111 }112 };113 const expected = Object.assign({}, DEFAULT_OPTIONS, {114 preload: {115 test: ['.js'],116 chunks: 'all'117 }118 });119 expect(normaliseOptions(options)).toEqual(expected);120 });121 it('handles full hash configuration with array for resource hint', () => {122 const options = {123 preload: {124 test: ['.js', /\*.js$/],125 chunks: 'all'126 }127 };128 const expected = Object.assign({}, DEFAULT_OPTIONS, {129 preload: {130 test: ['.js', /\*.js$/],131 chunks: 'all'132 }133 });134 expect(normaliseOptions(options)).toEqual(expected);135 });136 it('handles single no value custom attribute', () => {137 const options = {138 custom: {139 test: '*.js',140 attribute: 'wibble'141 }142 };143 const expected = Object.assign({}, DEFAULT_OPTIONS, {144 custom: [{145 test: ['*.js'],146 attribute: 'wibble',147 value: true148 }]149 });150 expect(normaliseOptions(options)).toEqual(expected);151 });152 it('handles single custom attribute with a value', () => {153 const options = {154 custom: {155 test: '*.js',156 attribute: 'wibble',157 value: 'wobble'158 }159 };160 const expected = Object.assign({}, DEFAULT_OPTIONS, {161 custom: [{162 test: ['*.js'],163 attribute: 'wibble',164 value: 'wobble'165 }]166 });167 expect(normaliseOptions(options)).toEqual(expected);168 });169 it('handles multiple custom attributes', () => {170 const options = {171 custom: [172 {173 test: '*.js',174 attribute: 'wibble'175 },176 {177 test: 'a',178 attribute: 'wobble',179 value: 'xyz'180 },181 {182 test: 'b',183 attribute: 'warble',184 value: 'grunf'185 }186 ]187 };188 const expected = Object.assign({}, DEFAULT_OPTIONS, {189 custom: [190 {191 test: ['*.js'],192 attribute: 'wibble',193 value: true194 },195 {196 test: ['a'],197 attribute: 'wobble',198 value: 'xyz'199 },200 {201 test: ['b'],202 attribute: 'warble',203 value: 'grunf'204 }205 ]206 });207 expect(normaliseOptions(options)).toEqual(expected);208 });209 it('works with webpack-config', () => {210 const config = new WebpackConfig().merge({211 plugins: [212 new ScriptExtHtmlWebpackPlugin({213 defaultAttribute: 'defer'214 })215 ]216 });217 expect(config.plugins[0].options.defaultAttribute).toEqual('defer');218 });...

Full Screen

Full Screen

index.spec.js

Source:index.spec.js Github

copy

Full Screen

...9 actual = undefined10 expected = Object.assign({}, DEFAULTS)11 })12 it('options is undefined', function() {13 actual = normaliseOptions()14 imp.expect(actual).to.eql(expected)15 })16 it('options is not an object', function() {17 actual = normaliseOptions(9)18 imp.expect(actual).to.eql(expected)19 })20 it('options is an empty object', function() {21 actual = normaliseOptions({})22 imp.expect(actual).to.eql(expected)23 })24 it('color is a boolean', function() {25 expected.color = true26 actual = normaliseOptions({color: true})27 imp.expect(actual).to.eql(expected)28 })29 it('color is not a boolean', function() {30 actual = normaliseOptions({color: 'false'})31 imp.expect(actual).to.eql(expected)32 })33 it('flags is a string', function() {34 expected.flags = 'woteva'35 actual = normaliseOptions({flags: ' woteva '})36 imp.expect(actual).to.eql(expected)37 })38 it('flags is null', function() {39 actual = normaliseOptions({flags: null})40 imp.expect(actual).to.eql(expected)41 })42 it('flags is not a string', function() {43 actual = normaliseOptions({flags: 9})44 imp.expect(actual).to.eql(expected)45 })46 it('forceFake is a boolean', function() {47 actual = normaliseOptions({forceFake: false})48 imp.expect(actual).to.eql(expected)49 })50 it('forceFake is not a boolean', function() {51 expected.forceFake = true52 actual = normaliseOptions({forceFake: 9})53 imp.expect(actual).to.eql(expected)54 })55 it('noHeaders is a boolean', function() {56 actual = normaliseOptions({noHeaders: false})57 imp.expect(actual).to.eql(expected)58 })59 it('noHeaders is not a boolean', function() {60 expected.noHeaders = true61 actual = normaliseOptions({noHeaders: 9})62 imp.expect(actual).to.eql(expected)63 })64 it('save', function() {65 var SAVE = true66 var WORD_DIFF = true67 imp.expect(DEFAULTS.save).to.equal(false)68 imp.expect(DEFAULTS.wordDiff).to.equal(false)69 expected.save = SAVE70 expected.wordDiff = WORD_DIFF71 actual = normaliseOptions({save: SAVE, wordDiff: WORD_DIFF})72 imp.expect(actual).to.eql(expected)73 imp.expect(DEFAULTS.save).to.equal(false)74 imp.expect(DEFAULTS.wordDiff).to.equal(WORD_DIFF)75 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var expect = chai.expect;3var assert = chai.assert;4var should = chai.should();5var chaiAsPromised = require("chai-as-promised");6chai.use(chaiAsPromised);7var chaiHttp = require('chai-http');8chai.use(chaiHttp);9var chaiSubset = require('chai-subset');10chai.use(chaiSubset);11var chaiJsonSchema = require('chai-json-schema');12chai.use(chaiJsonSchema);13var chaiString = require('chai-string');14chai.use(chaiString);15var chaiDatetime = require('chai-datetime');16chai.use(chaiDatetime);17var chaiSpies = require('chai-spies');18chai.use(chaiSpies);19var chaiThings = require('chai-things');20chai.use(chaiThings);21var chaiLike = require('chai-like');22chai.use(chaiLike);23var chaiJoi = require('chai-joi');24chai.use(chaiJoi);25var chaiAsPromised = require('chai-as-promised');26chai.use(chaiAsPromised);27var chaiExclude = require('chai-exclude');28chai.use(chaiExclude);29var chaiJsonEqual = require('chai-json-equal');30chai.use(chaiJsonEqual);31var chaiJsonPattern = require('chai-json-pattern');32chai.use(chaiJsonPattern);33var chaiMatchPattern = require('chai-match-pattern');34chai.use(chaiMatchPattern);35var chaiMatch = require('chai-match');36chai.use(chaiMatch);37var chaiImmutable = require('chai-immutable');38chai.use(chaiImmutable);39var chaiEnzyme = require('chai-enzyme');40chai.use(chaiEnzyme);41var chaiChange = require('chai-change');42chai.use(chaiChange);43var chaiAsPromised = require('chai-as-promised');44chai.use(chaiAsPromised);45var chaiJestSnapshot = require('chai-jest-snapshot');46chai.use(chaiJestSnapshot);47var chaiVagueErrors = require('chai-vague-errors');48chai.use(chaiVagueErrors);49var chaiJestDiff = require('chai-jest-diff');50chai.use(chaiJestDiff);51var chaiJsonEqual = require('chai-json-equal');52chai.use(chaiJsonEqual);53var chaiJsonSchema = require('chai-json-schema');54chai.use(chaiJsonSchema);55var chaiAsPromised = require('chai-as-promised');56chai.use(chaiAsPromised);

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var expect = chai.expect;3var assert = chai.assert;4var should = chai.should();5var chaiSubset = require('chai-subset');6chai.use(chaiSubset);7var chaiAsPromised = require('chai-as-promised');8chai.use(chaiAsPromised);9var chaiHttp = require('chai-http');10chai.use(chaiHttp);11var chaiJsonEqual = require('chai-json-equal');12chai.use(chaiJsonEqual);13var chaiJsonPattern = require('chai-json-pattern');14chai.use(chaiJsonPattern);15var chaiJsonSchema = require('chai-json-schema');16chai.use(chaiJsonSchema);17var chaiJsonInclude = require('chai-json-include');18chai.use(chaiJsonInclude);19var chaiJsonSchema = require('chai-json-schema');20chai.use(chaiJsonSchema);21var chaiJsonSchema = require('chai-json-schema');22chai.use(chaiJsonSchema);23var chaiJsonSchema = require('chai-json-schema');24chai.use(chaiJsonSchema);25var chai = require('chai');26var expect = chai.expect;27var assert = chai.assert;28var should = chai.should();29var chaiSubset = require('chai-subset');30chai.use(chaiSubset);31var chaiAsPromised = require('chai-as-promised');32chai.use(chaiAsPromised);33var chaiHttp = require('chai-http');34chai.use(chaiHttp);35var chaiJsonEqual = require('chai-json-equal');36chai.use(chaiJsonEqual);37var chaiJsonPattern = require('chai-json-pattern');38chai.use(chaiJsonPattern);39var chaiJsonSchema = require('chai-json-schema');40chai.use(chaiJsonSchema);41var chaiJsonInclude = require('chai-json-include');42chai.use(chaiJsonInclude);43var chaiJsonSchema = require('chai-json-schema');44chai.use(chaiJsonSchema);45var chaiJsonSchema = require('chai-json-schema');46chai.use(chaiJsonSchema);47var chaiJsonSchema = require('chai-json-schema');48chai.use(chaiJsonSchema);49var chai = require('chai');50var expect = chai.expect;51var assert = chai.assert;52var should = chai.should();53var chaiSubset = require('chai-subset');54chai.use(chaiSubset);55var chaiAsPromised = require('chai-as-promised');56chai.use(chaiAsPromised);

Full Screen

Using AI Code Generation

copy

Full Screen

1const chai = require('chai');2const { normaliseOptions } = chai.Assertion;3const chai = require('chai');4const { normaliseOptions } = chai.Assertion;5const chai = require('chai');6const { normaliseOptions } = chai.Assertion;7const chai = require('chai');8const { normaliseOptions } = chai.Assertion;9const chai = require('chai');10const { normaliseOptions } = chai.Assertion;11const chai = require('chai');12const { normaliseOptions } = chai.Assertion;13const chai = require('chai');14const { normaliseOptions } = chai.Assertion;15const chai = require('chai');16const { normaliseOptions } = chai.Assertion;17const chai = require('chai');18const { normaliseOptions } = chai.Assertion;19const chai = require('chai');20const { normaliseOptions } = chai.Assertion;21const chai = require('chai');22const { normaliseOptions } = chai.Assertion;

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var expect = chai.expect;3var assert = chai.assert;4var should = chai.should();5var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');6var options = {a: 'a', b: 'b'};7var normalisedOptions = normaliseOptions(options);8console.log(normalisedOptions);9var chai = require('chai');10var expect = chai.expect;11var assert = chai.assert;12var should = chai.should();13var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');14var options = {a: 'a', b: 'b', showDiff: false};15var normalisedOptions = normaliseOptions(options);16console.log(normalisedOptions);17var chai = require('chai');18var expect = chai.expect;19var assert = chai.assert;20var should = chai.should();21var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');22var options = {a: 'a', b: 'b', showDiff: true};23var normalisedOptions = normaliseOptions(options);24console.log(normalisedOptions);25var chai = require('chai');26var expect = chai.expect;27var assert = chai.assert;28var should = chai.should();29var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');30var options = {a: 'a', b: 'b', showDiff: 'true'};31var normalisedOptions = normaliseOptions(options);32console.log(normalisedOptions);33var chai = require('chai');34var expect = chai.expect;35var assert = chai.assert;36var should = chai.should();37var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');38var options = {a: 'a

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var expect = chai.expect;3var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');4describe('normaliseOptions', function() {5 it('should return an object', function() {6 expect(normaliseOptions()).to.be.an('object');7 });8});9var chai = require('chai');10var expect = chai.expect;11var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');12describe('normaliseOptions', function() {13 it('should return an object', function() {14 expect(normaliseOptions()).to.be.an('object');15 });16});17var chai = require('chai');18var expect = chai.expect;19var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');20describe('normaliseOptions', function() {21 it('should return an object', function() {22 expect(normaliseOptions()).to.be.an('object');23 });24});25var chai = require('chai');26var expect = chai.expect;27var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');28describe('normaliseOptions', function() {29 it('should return an object', function() {30 expect(normaliseOptions()).to.be.an('object');31 });32});33var chai = require('chai');34var expect = chai.expect;35var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');36describe('normaliseOptions', function() {37 it('should return an object', function() {38 expect(normaliseOptions()).to.be.an('object');39 });40});41var chai = require('chai');42var expect = chai.expect;43var normaliseOptions = require('chai/lib/chai/utils/normaliseOptions');44describe('normaliseOptions', function() {45 it('should return an object', function() {46 expect(normaliseOptions

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var expect = chai.expect;3var assert = chai.assert;4var options = {5};6var expected = {7};8var normalisedOptions = chai.util.normaliseOptions(options, expected);9console.log(normalisedOptions);10{ a: 1, b: 2, c: 3, d: 4 }11{ a: 1, b: 2, c: 3, d: 4 }12{ a: 1, b: 2, c: 3, d: 4 }13{ a: 1, b: 2, c: 3, d: 4 }14{ a: 1, b: 2, c: 3, d: 4 }15{ a: 1, b: 2, c: 3, d: 4 }

Full Screen

Using AI Code Generation

copy

Full Screen

1const chai = require('chai');2const normaliseOptions = chai.Assertion.prototype._normaliseOptions;3const assert = chai.assert;4describe('normaliseOptions', () => {5 it('should return a string when passed a string', () => {6 assert.equal(normaliseOptions('string'), 'string');7 });8 it('should return a string when passed a number', () => {9 assert.equal(normaliseOptions(10), '10');10 });11 it('should return a string when passed a boolean', () => {12 assert.equal(normaliseOptions(true), 'true');13 });14 it('should return a string when passed null', () => {15 assert.equal(normaliseOptions(null), 'null');16 });17 it('should return a string when passed undefined', () => {18 assert.equal(normaliseOptions(undefined), 'undefined');19 });20 it('should return a string when passed a function', () => {21 assert.equal(normaliseOptions(function() {}), 'function () {}');22 });23 it('should return a string when passed an object', () => {24 assert.equal(25 normaliseOptions({26 }),27 '{ a: 1, b: 2 }'28 );29 });30 it('should return a string when passed an array', () => {31 assert.equal(normaliseOptions([1, 2, 3]), '[ 1, 2, 3 ]');32 });33});34const chai = require('chai');35const normaliseOptions = chai.Assertion.prototype._normaliseOptions;36const assert = chai.assert;37describe('normaliseOptions', () => {38 it('should return a string when passed a string', () => {39 assert.equal(normaliseOptions('string'), 'string');40 });41 it('should return a string when passed a number', () => {42 assert.equal(normaliseOptions(10), '10');43 });44 it('should return a string when passed a boolean', () => {45 assert.equal(normaliseOptions(true), 'true');46 });47 it('should return a string when passed null', () => {48 assert.equal(normaliseOptions(null), 'null');49 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var expect = chai.expect;3var assert = chai.assert;4var should = chai.should();5var normaliseOptions = require('../index.js').normaliseOptions;6var options = {7};8var defaultOptions = {9};10describe('normaliseOptions', function() {11 it('should return the default options if options is undefined', function() {12 var normalisedOptions = normaliseOptions(undefined, defaultOptions);13 expect(normalisedOptions).to.deep.equal(defaultOptions);14 });15 it('should return the default options if options is null', function() {16 var normalisedOptions = normaliseOptions(null, defaultOptions);17 expect(normalisedOptions).to.deep.equal(defaultOptions);18 });19 it('should return the default options if options is empty object', function() {20 var normalisedOptions = normaliseOptions({}, defaultOptions);21 expect(normalisedOptions).to.deep.equal(defaultOptions);22 });23 it('should return the default options if options is empty array', function() {24 var normalisedOptions = normaliseOptions([], defaultOptions);25 expect(normalisedOptions).to.deep.equal(defaultOptions);26 });27 it('should return the default options if options is empty string', function() {28 var normalisedOptions = normaliseOptions('', defaultOptions);29 expect(normalisedOptions).to.deep.equal(defaultOptions);30 });31 it('should return the default options if options is number', function() {32 var normalisedOptions = normaliseOptions(10, defaultOptions);33 expect(normalisedOptions).to.deep.equal(defaultOptions);34 });35 it('should return the default options if options is boolean', function() {36 var normalisedOptions = normaliseOptions(true, defaultOptions);37 expect(normalisedOptions).to.deep.equal(defaultOptions);38 });39 it('should return the default options if options is NaN', function() {40 var normalisedOptions = normaliseOptions(NaN, defaultOptions);41 expect(normalisedOptions).to.deep.equal(defaultOptions);42 });43 it('should return the default options if options is Infinity', function() {44 var normalisedOptions = normaliseOptions(Infinity, defaultOptions);45 expect(normalisedOptions).to.deep.equal(defaultOptions);46 });

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run chai automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful