Best JavaScript code snippet using ng-mocks
extHostConfiguration.test.ts
Source:extHostConfiguration.test.ts
1/*---------------------------------------------------------------------------------------------2 * Copyright (c) Microsoft Corporation. All rights reserved.3 * Licensed under the MIT License. See License.txt in the project root for license information.4 *--------------------------------------------------------------------------------------------*/5import * as assert from 'assert';6import { URI } from 'vs/base/common/uri';7import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';8import { ExtHostConfigProvider } from 'vs/workbench/api/node/extHostConfiguration';9import { MainThreadConfigurationShape, IConfigurationInitData } from 'vs/workbench/api/common/extHost.protocol';10import { ConfigurationModel } from 'vs/platform/configuration/common/configurationModels';11import { TestRPCProtocol } from './testRPCProtocol';12import { mock } from 'vs/workbench/test/electron-browser/api/mock';13import { IWorkspaceFolder, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';14import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';15import { NullLogService } from 'vs/platform/log/common/log';16import { assign } from 'vs/base/common/objects';17import { Counter } from 'vs/base/common/numbers';18suite('ExtHostConfiguration', function () {19 class RecordingShape extends mock<MainThreadConfigurationShape>() {20 lastArgs: [ConfigurationTarget, string, any];21 $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<void> {22 this.lastArgs = [target, key, value];23 return Promise.resolve(undefined);24 }25 }26 function createExtHostConfiguration(contents: any = Object.create(null), shape?: MainThreadConfigurationShape) {27 if (!shape) {28 shape = new class extends mock<MainThreadConfigurationShape>() { };29 }30 return new ExtHostConfigProvider(shape, new ExtHostWorkspace(new TestRPCProtocol(), new NullLogService(), new Counter()), createConfigurationData(contents));31 }32 function createConfigurationData(contents: any): IConfigurationInitData {33 return {34 defaults: new ConfigurationModel(contents),35 user: new ConfigurationModel(contents),36 workspace: new ConfigurationModel(),37 folders: Object.create(null),38 configurationScopes: {},39 isComplete: true40 };41 }42 test('getConfiguration fails regression test 1.7.1 -> 1.8 #15552', function () {43 const extHostConfig = createExtHostConfiguration({44 'search': {45 'exclude': {46 '**/node_modules': true47 }48 }49 });50 assert.equal(extHostConfig.getConfiguration('search.exclude')['**/node_modules'], true);51 assert.equal(extHostConfig.getConfiguration('search.exclude').get('**/node_modules'), true);52 assert.equal(extHostConfig.getConfiguration('search').get<any>('exclude')['**/node_modules'], true);53 assert.equal(extHostConfig.getConfiguration('search.exclude').has('**/node_modules'), true);54 assert.equal(extHostConfig.getConfiguration('search').has('exclude.**/node_modules'), true);55 });56 test('has/get', () => {57 const all = createExtHostConfiguration({58 'farboo': {59 'config0': true,60 'nested': {61 'config1': 42,62 'config2': 'Das Pferd frisst kein Reis.'63 },64 'config4': ''65 }66 });67 const config = all.getConfiguration('farboo');68 assert.ok(config.has('config0'));69 assert.equal(config.get('config0'), true);70 assert.equal(config.get('config4'), '');71 assert.equal(config['config0'], true);72 assert.equal(config['config4'], '');73 assert.ok(config.has('nested.config1'));74 assert.equal(config.get('nested.config1'), 42);75 assert.ok(config.has('nested.config2'));76 assert.equal(config.get('nested.config2'), 'Das Pferd frisst kein Reis.');77 assert.ok(config.has('nested'));78 assert.deepEqual(config.get('nested'), { config1: 42, config2: 'Das Pferd frisst kein Reis.' });79 });80 test('can modify the returned configuration', function () {81 const all = createExtHostConfiguration({82 'farboo': {83 'config0': true,84 'nested': {85 'config1': 42,86 'config2': 'Das Pferd frisst kein Reis.'87 },88 'config4': ''89 },90 'workbench': {91 'colorCustomizations': {92 'statusBar.foreground': 'somevalue'93 }94 }95 });96 let testObject = all.getConfiguration();97 let actual = testObject.get<any>('farboo')!;98 actual['nested']['config1'] = 41;99 assert.equal(41, actual['nested']['config1']);100 actual['farboo1'] = 'newValue';101 assert.equal('newValue', actual['farboo1']);102 testObject = all.getConfiguration();103 actual = testObject.get('farboo')!;104 assert.equal(actual['nested']['config1'], 42);105 assert.equal(actual['farboo1'], undefined);106 testObject = all.getConfiguration();107 actual = testObject.get('farboo')!;108 assert.equal(actual['config0'], true);109 actual['config0'] = false;110 assert.equal(actual['config0'], false);111 testObject = all.getConfiguration();112 actual = testObject.get('farboo')!;113 assert.equal(actual['config0'], true);114 testObject = all.getConfiguration();115 actual = testObject.inspect('farboo')!;116 actual['value'] = 'effectiveValue';117 assert.equal('effectiveValue', actual['value']);118 testObject = all.getConfiguration('workbench');119 actual = testObject.get('colorCustomizations')!;120 delete actual['statusBar.foreground'];121 assert.equal(actual['statusBar.foreground'], undefined);122 testObject = all.getConfiguration('workbench');123 actual = testObject.get('colorCustomizations')!;124 assert.equal(actual['statusBar.foreground'], 'somevalue');125 });126 test('Stringify returned configuration', function () {127 const all = createExtHostConfiguration({128 'farboo': {129 'config0': true,130 'nested': {131 'config1': 42,132 'config2': 'Das Pferd frisst kein Reis.'133 },134 'config4': ''135 },136 'workbench': {137 'colorCustomizations': {138 'statusBar.foreground': 'somevalue'139 },140 'emptyobjectkey': {141 }142 }143 });144 const testObject = all.getConfiguration();145 let actual: any = testObject.get('farboo');146 assert.deepEqual(JSON.stringify({147 'config0': true,148 'nested': {149 'config1': 42,150 'config2': 'Das Pferd frisst kein Reis.'151 },152 'config4': ''153 }), JSON.stringify(actual));154 assert.deepEqual(undefined, JSON.stringify(testObject.get('unknownkey')));155 actual = testObject.get('farboo')!;156 actual['config0'] = false;157 assert.deepEqual(JSON.stringify({158 'config0': false,159 'nested': {160 'config1': 42,161 'config2': 'Das Pferd frisst kein Reis.'162 },163 'config4': ''164 }), JSON.stringify(actual));165 actual = testObject.get<any>('workbench')!['colorCustomizations']!;166 actual['statusBar.background'] = 'anothervalue';167 assert.deepEqual(JSON.stringify({168 'statusBar.foreground': 'somevalue',169 'statusBar.background': 'anothervalue'170 }), JSON.stringify(actual));171 actual = testObject.get('workbench');172 actual['unknownkey'] = 'somevalue';173 assert.deepEqual(JSON.stringify({174 'colorCustomizations': {175 'statusBar.foreground': 'somevalue'176 },177 'emptyobjectkey': {},178 'unknownkey': 'somevalue'179 }), JSON.stringify(actual));180 actual = all.getConfiguration('workbench').get('emptyobjectkey');181 actual = assign(actual || {}, {182 'statusBar.background': `#0ff`,183 'statusBar.foreground': `#ff0`,184 });185 assert.deepEqual(JSON.stringify({186 'statusBar.background': `#0ff`,187 'statusBar.foreground': `#ff0`,188 }), JSON.stringify(actual));189 actual = all.getConfiguration('workbench').get('unknownkey');190 actual = assign(actual || {}, {191 'statusBar.background': `#0ff`,192 'statusBar.foreground': `#ff0`,193 });194 assert.deepEqual(JSON.stringify({195 'statusBar.background': `#0ff`,196 'statusBar.foreground': `#ff0`,197 }), JSON.stringify(actual));198 });199 test('cannot modify returned configuration', function () {200 const all = createExtHostConfiguration({201 'farboo': {202 'config0': true,203 'nested': {204 'config1': 42,205 'config2': 'Das Pferd frisst kein Reis.'206 },207 'config4': ''208 }209 });210 let testObject: any = all.getConfiguration();211 try {212 testObject['get'] = null;213 assert.fail('This should be readonly');214 } catch (e) {215 }216 try {217 testObject['farboo']['config0'] = false;218 assert.fail('This should be readonly');219 } catch (e) {220 }221 try {222 testObject['farboo']['farboo1'] = 'hello';223 assert.fail('This should be readonly');224 } catch (e) {225 }226 });227 test('inspect in no workspace context', function () {228 const testObject = new ExtHostConfigProvider(229 new class extends mock<MainThreadConfigurationShape>() { },230 new ExtHostWorkspace(new TestRPCProtocol(), new NullLogService(), new Counter()),231 {232 defaults: new ConfigurationModel({233 'editor': {234 'wordWrap': 'off'235 }236 }, ['editor.wordWrap']),237 user: new ConfigurationModel({238 'editor': {239 'wordWrap': 'on'240 }241 }, ['editor.wordWrap']),242 workspace: new ConfigurationModel({}, []),243 folders: Object.create(null),244 configurationScopes: {},245 isComplete: true246 }247 );248 let actual = testObject.getConfiguration().inspect('editor.wordWrap')!;249 assert.equal(actual.defaultValue, 'off');250 assert.equal(actual.globalValue, 'on');251 assert.equal(actual.workspaceValue, undefined);252 assert.equal(actual.workspaceFolderValue, undefined);253 actual = testObject.getConfiguration('editor').inspect('wordWrap')!;254 assert.equal(actual.defaultValue, 'off');255 assert.equal(actual.globalValue, 'on');256 assert.equal(actual.workspaceValue, undefined);257 assert.equal(actual.workspaceFolderValue, undefined);258 });259 test('inspect in single root context', function () {260 const workspaceUri = URI.file('foo');261 const folders = Object.create(null);262 const workspace = new ConfigurationModel({263 'editor': {264 'wordWrap': 'bounded'265 }266 }, ['editor.wordWrap']);267 folders[workspaceUri.toString()] = workspace;268 const extHostWorkspace = new ExtHostWorkspace(new TestRPCProtocol(), new NullLogService(), new Counter());269 extHostWorkspace.$initializeWorkspace({270 'id': 'foo',271 'folders': [aWorkspaceFolder(URI.file('foo'), 0)],272 'name': 'foo'273 });274 const testObject = new ExtHostConfigProvider(275 new class extends mock<MainThreadConfigurationShape>() { },276 extHostWorkspace,277 {278 defaults: new ConfigurationModel({279 'editor': {280 'wordWrap': 'off'281 }282 }, ['editor.wordWrap']),283 user: new ConfigurationModel({284 'editor': {285 'wordWrap': 'on'286 }287 }, ['editor.wordWrap']),288 workspace,289 folders,290 configurationScopes: {},291 isComplete: true292 }293 );294 let actual1 = testObject.getConfiguration().inspect('editor.wordWrap')!;295 assert.equal(actual1.defaultValue, 'off');296 assert.equal(actual1.globalValue, 'on');297 assert.equal(actual1.workspaceValue, 'bounded');298 assert.equal(actual1.workspaceFolderValue, undefined);299 actual1 = testObject.getConfiguration('editor').inspect('wordWrap')!;300 assert.equal(actual1.defaultValue, 'off');301 assert.equal(actual1.globalValue, 'on');302 assert.equal(actual1.workspaceValue, 'bounded');303 assert.equal(actual1.workspaceFolderValue, undefined);304 let actual2 = testObject.getConfiguration(undefined, workspaceUri).inspect('editor.wordWrap')!;305 assert.equal(actual2.defaultValue, 'off');306 assert.equal(actual2.globalValue, 'on');307 assert.equal(actual2.workspaceValue, 'bounded');308 assert.equal(actual2.workspaceFolderValue, 'bounded');309 actual2 = testObject.getConfiguration('editor', workspaceUri).inspect('wordWrap')!;310 assert.equal(actual2.defaultValue, 'off');311 assert.equal(actual2.globalValue, 'on');312 assert.equal(actual2.workspaceValue, 'bounded');313 assert.equal(actual2.workspaceFolderValue, 'bounded');314 });315 test('inspect in multi root context', function () {316 const workspace = new ConfigurationModel({317 'editor': {318 'wordWrap': 'bounded'319 }320 }, ['editor.wordWrap']);321 const firstRoot = URI.file('foo1');322 const secondRoot = URI.file('foo2');323 const thirdRoot = URI.file('foo3');324 const folders = Object.create(null);325 folders[firstRoot.toString()] = new ConfigurationModel({326 'editor': {327 'wordWrap': 'off',328 'lineNumbers': 'relative'329 }330 }, ['editor.wordWrap']);331 folders[secondRoot.toString()] = new ConfigurationModel({332 'editor': {333 'wordWrap': 'on'334 }335 }, ['editor.wordWrap']);336 folders[thirdRoot.toString()] = new ConfigurationModel({}, []);337 const extHostWorkspace = new ExtHostWorkspace(new TestRPCProtocol(), new NullLogService(), new Counter());338 extHostWorkspace.$initializeWorkspace({339 'id': 'foo',340 'folders': [aWorkspaceFolder(firstRoot, 0), aWorkspaceFolder(secondRoot, 1)],341 'name': 'foo'342 });343 const testObject = new ExtHostConfigProvider(344 new class extends mock<MainThreadConfigurationShape>() { },345 extHostWorkspace,346 {347 defaults: new ConfigurationModel({348 'editor': {349 'wordWrap': 'off',350 'lineNumbers': 'on'351 }352 }, ['editor.wordWrap']),353 user: new ConfigurationModel({354 'editor': {355 'wordWrap': 'on'356 }357 }, ['editor.wordWrap']),358 workspace,359 folders,360 configurationScopes: {},361 isComplete: true362 }363 );364 let actual1 = testObject.getConfiguration().inspect('editor.wordWrap')!;365 assert.equal(actual1.defaultValue, 'off');366 assert.equal(actual1.globalValue, 'on');367 assert.equal(actual1.workspaceValue, 'bounded');368 assert.equal(actual1.workspaceFolderValue, undefined);369 actual1 = testObject.getConfiguration('editor').inspect('wordWrap')!;370 assert.equal(actual1.defaultValue, 'off');371 assert.equal(actual1.globalValue, 'on');372 assert.equal(actual1.workspaceValue, 'bounded');373 assert.equal(actual1.workspaceFolderValue, undefined);374 actual1 = testObject.getConfiguration('editor').inspect('lineNumbers')!;375 assert.equal(actual1.defaultValue, 'on');376 assert.equal(actual1.globalValue, undefined);377 assert.equal(actual1.workspaceValue, undefined);378 assert.equal(actual1.workspaceFolderValue, undefined);379 let actual2 = testObject.getConfiguration(undefined, firstRoot).inspect('editor.wordWrap')!;380 assert.equal(actual2.defaultValue, 'off');381 assert.equal(actual2.globalValue, 'on');382 assert.equal(actual2.workspaceValue, 'bounded');383 assert.equal(actual2.workspaceFolderValue, 'off');384 actual2 = testObject.getConfiguration('editor', firstRoot).inspect('wordWrap')!;385 assert.equal(actual2.defaultValue, 'off');386 assert.equal(actual2.globalValue, 'on');387 assert.equal(actual2.workspaceValue, 'bounded');388 assert.equal(actual2.workspaceFolderValue, 'off');389 actual2 = testObject.getConfiguration('editor', firstRoot).inspect('lineNumbers')!;390 assert.equal(actual2.defaultValue, 'on');391 assert.equal(actual2.globalValue, undefined);392 assert.equal(actual2.workspaceValue, undefined);393 assert.equal(actual2.workspaceFolderValue, 'relative');394 actual2 = testObject.getConfiguration(undefined, secondRoot).inspect('editor.wordWrap')!;395 assert.equal(actual2.defaultValue, 'off');396 assert.equal(actual2.globalValue, 'on');397 assert.equal(actual2.workspaceValue, 'bounded');398 assert.equal(actual2.workspaceFolderValue, 'on');399 actual2 = testObject.getConfiguration('editor', secondRoot).inspect('wordWrap')!;400 assert.equal(actual2.defaultValue, 'off');401 assert.equal(actual2.globalValue, 'on');402 assert.equal(actual2.workspaceValue, 'bounded');403 assert.equal(actual2.workspaceFolderValue, 'on');404 actual2 = testObject.getConfiguration(undefined, thirdRoot).inspect('editor.wordWrap')!;405 assert.equal(actual2.defaultValue, 'off');406 assert.equal(actual2.globalValue, 'on');407 assert.equal(actual2.workspaceValue, 'bounded');408 assert.ok(Object.keys(actual2).indexOf('workspaceFolderValue') !== -1);409 assert.equal(actual2.workspaceFolderValue, undefined);410 actual2 = testObject.getConfiguration('editor', thirdRoot).inspect('wordWrap')!;411 assert.equal(actual2.defaultValue, 'off');412 assert.equal(actual2.globalValue, 'on');413 assert.equal(actual2.workspaceValue, 'bounded');414 assert.ok(Object.keys(actual2).indexOf('workspaceFolderValue') !== -1);415 assert.equal(actual2.workspaceFolderValue, undefined);416 });417 test('getConfiguration vs get', function () {418 const all = createExtHostConfiguration({419 'farboo': {420 'config0': true,421 'config4': 38422 }423 });424 let config = all.getConfiguration('farboo.config0');425 assert.equal(config.get(''), undefined);426 assert.equal(config.has(''), false);427 config = all.getConfiguration('farboo');428 assert.equal(config.get('config0'), true);429 assert.equal(config.has('config0'), true);430 });431 test('getConfiguration vs get', function () {432 const all = createExtHostConfiguration({433 'farboo': {434 'config0': true,435 'config4': 38436 }437 });438 let config = all.getConfiguration('farboo.config0');439 assert.equal(config.get(''), undefined);440 assert.equal(config.has(''), false);441 config = all.getConfiguration('farboo');442 assert.equal(config.get('config0'), true);443 assert.equal(config.has('config0'), true);444 });445 test('name vs property', function () {446 const all = createExtHostConfiguration({447 'farboo': {448 'get': 'get-prop'449 }450 });451 const config = all.getConfiguration('farboo');452 assert.ok(config.has('get'));453 assert.equal(config.get('get'), 'get-prop');454 assert.deepEqual(config['get'], config.get);455 assert.throws(() => config['get'] = <any>'get-prop');456 });457 test('update: no target passes null', function () {458 const shape = new RecordingShape();459 const allConfig = createExtHostConfiguration({460 'foo': {461 'bar': 1,462 'far': 1463 }464 }, shape);465 let config = allConfig.getConfiguration('foo');466 config.update('bar', 42);467 assert.equal(shape.lastArgs[0], null);468 });469 test('update/section to key', function () {470 const shape = new RecordingShape();471 const allConfig = createExtHostConfiguration({472 'foo': {473 'bar': 1,474 'far': 1475 }476 }, shape);477 let config = allConfig.getConfiguration('foo');478 config.update('bar', 42, true);479 assert.equal(shape.lastArgs[0], ConfigurationTarget.USER);480 assert.equal(shape.lastArgs[1], 'foo.bar');481 assert.equal(shape.lastArgs[2], 42);482 config = allConfig.getConfiguration('');483 config.update('bar', 42, true);484 assert.equal(shape.lastArgs[1], 'bar');485 config.update('foo.bar', 42, true);486 assert.equal(shape.lastArgs[1], 'foo.bar');487 });488 test('update, what is #15834', function () {489 const shape = new RecordingShape();490 const allConfig = createExtHostConfiguration({491 'editor': {492 'formatOnSave': true493 }494 }, shape);495 allConfig.getConfiguration('editor').update('formatOnSave', { extensions: ['ts'] });496 assert.equal(shape.lastArgs[1], 'editor.formatOnSave');497 assert.deepEqual(shape.lastArgs[2], { extensions: ['ts'] });498 });499 test('update/error-state not OK', function () {500 const shape = new class extends mock<MainThreadConfigurationShape>() {501 $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<any> {502 return Promise.reject(new Error('Unknown Key')); // something !== OK503 }504 };505 return createExtHostConfiguration({}, shape)506 .getConfiguration('')507 .update('', true, false)508 .then(() => assert.ok(false), err => { /* expecting rejection */ });509 });510 test('configuration change event', (done) => {511 const workspaceFolder = aWorkspaceFolder(URI.file('folder1'), 0);512 const extHostWorkspace = new ExtHostWorkspace(new TestRPCProtocol(), new NullLogService(), new Counter());513 extHostWorkspace.$initializeWorkspace({514 'id': 'foo',515 'folders': [workspaceFolder],516 'name': 'foo'517 });518 const testObject = new ExtHostConfigProvider(519 new class extends mock<MainThreadConfigurationShape>() { },520 extHostWorkspace,521 createConfigurationData({522 'farboo': {523 'config': false,524 'updatedconfig': false525 }526 })527 );528 const newConfigData = createConfigurationData({529 'farboo': {530 'config': false,531 'updatedconfig': true,532 'newConfig': true,533 }534 });535 const changedConfigurationByResource = Object.create({});536 changedConfigurationByResource[workspaceFolder.uri.toString()] = new ConfigurationModel({537 'farboo': {538 'newConfig': true,539 }540 }, ['farboo.newConfig']);541 const configEventData = {542 changedConfiguration: new ConfigurationModel({543 'farboo': {544 'updatedConfig': true,545 }546 }, ['farboo.updatedConfig']),547 changedConfigurationByResource548 };549 testObject.onDidChangeConfiguration(e => {550 assert.deepEqual(testObject.getConfiguration().get('farboo'), {551 'config': false,552 'updatedconfig': true,553 'newConfig': true,554 });555 assert.ok(e.affectsConfiguration('farboo'));556 assert.ok(e.affectsConfiguration('farboo', workspaceFolder.uri));557 assert.ok(e.affectsConfiguration('farboo', URI.file('any')));558 assert.ok(e.affectsConfiguration('farboo.updatedConfig'));559 assert.ok(e.affectsConfiguration('farboo.updatedConfig', workspaceFolder.uri));560 assert.ok(e.affectsConfiguration('farboo.updatedConfig', URI.file('any')));561 assert.ok(e.affectsConfiguration('farboo.newConfig'));562 assert.ok(e.affectsConfiguration('farboo.newConfig', workspaceFolder.uri));563 assert.ok(!e.affectsConfiguration('farboo.newConfig', URI.file('any')));564 assert.ok(!e.affectsConfiguration('farboo.config'));565 assert.ok(!e.affectsConfiguration('farboo.config', workspaceFolder.uri));566 assert.ok(!e.affectsConfiguration('farboo.config', URI.file('any')));567 done();568 });569 testObject.$acceptConfigurationChanged(newConfigData, configEventData);570 });571 function aWorkspaceFolder(uri: URI, index: number, name: string = ''): IWorkspaceFolder {572 return new WorkspaceFolder({ uri, name, index });573 }...
custom-set.spec.js
Source:custom-set.spec.js
1var CustomSet = require('./custom-set');2describe('CustomSet', function() {3 it('can delete elements', function(){4 var expected = new CustomSet([1, 3]);5 var actual = new CustomSet([3, 2, 1]).delete(2);6 expect(actual.eql(expected)).toBe(true);7 var expected2 = new CustomSet([1, 2, 3]);8 var actual2 = new CustomSet([3, 2, 1]).delete(4);9 expect(actual2.eql(expected2)).toBe(true);10 });11 it('can check for difference', function(){12 var expected = new CustomSet([1, 3]);13 var actual = new CustomSet([3, 2, 1]).difference(new CustomSet([2, 4]));14 expect(actual.eql(expected)).toBe(true);15 var expected2 = new CustomSet([1, 2, 3]);16 var actual2 = new CustomSet([1, 2, 3]).difference(new CustomSet([4]));17 expect(actual2.eql(expected2)).toBe(true);18 });19 it('can test disjoint', function() {20 var actual = new CustomSet([1, 2]).disjoint(new CustomSet([3, 4]));21 expect(actual).toBe(true);22 var actual2 = new CustomSet([1, 2]).disjoint(new CustomSet([2, 3]));23 expect(actual2).toBe(false);24 var actual3 = new CustomSet().disjoint(new CustomSet());25 expect(actual3).toBe(true);26 });27 it('can be emptied', function() {28 var actual = new CustomSet([1, 2]).empty();29 var expected = new CustomSet();30 expect(actual.eql(expected)).toBe(true);31 var actual2 = new CustomSet().empty();32 var expected2 = new CustomSet();33 expect(actual2.eql(expected2)).toBe(true);34 });35 it('can check for intersection', function() {36 var actual = new CustomSet(['a', 'b', 'c']).intersection(new CustomSet(['a', 'c', 'd']));37 var expected = new CustomSet(['a', 'c']);38 expect(actual.eql(expected)).toBe(true);39 var actual2 = new CustomSet([1, 2, 3]).intersection(new CustomSet([3, 5, 4]));40 var expected2 = new CustomSet([3]);41 expect(actual2.eql(expected2)).toBe(true);42 });43 it('can test for a member', function() {44 var actual = new CustomSet([1, 2, 3]).member(2);45 expect(actual).toBe(true);46 var actual2 = new CustomSet([1, 2, 3]).member(4);47 expect(actual2).toBe(false);48 });49 it('can add a member with put', function() {50 var actual = new CustomSet([1, 2, 4]).put(3);51 var expected = new CustomSet([1, 2, 3, 4]);52 expect(actual.eql(expected)).toBe(true);53 var actual2 = new CustomSet([1, 2, 3]).put(3);54 var expected2 = new CustomSet([1, 2, 3]);55 expect(actual2.eql(expected2)).toBe(true);56 });57 it('knows its size', function() {58 var actual = new CustomSet().size();59 expect(actual).toBe(0);60 var actual2 = new CustomSet([1, 2, 3]).size();61 expect(actual2).toBe(3);62 var actual3 = new CustomSet([1, 2, 3, 2]).size();63 expect(actual3).toBe(3);64 });65 it('can test for subsets', function() {66 var actual = new CustomSet([1, 2, 3]).subset(new CustomSet([1, 2, 3]));67 expect(actual).toBe(true);68 var actual2 = new CustomSet([4, 1, 2, 3]).subset(new CustomSet([1, 2, 3]));69 expect(actual2).toBe(true);70 var actual3 = new CustomSet([4, 1, 3]).subset(new CustomSet([1, 2, 3]));71 expect(actual3).toBe(false);72 var actual4 = new CustomSet([4, 1, 3]).subset(new CustomSet());73 expect(actual4).toBe(true);74 var actual5 = new CustomSet().subset(new CustomSet());75 expect(actual5).toBe(true);76 });77 it('can give back a list', function() {78 var actual = new CustomSet().toList();79 var expected = [];80 expect(actual.sort()).toEqual(expected);81 var actual2 = new CustomSet([3, 1, 2]).toList();82 var expected2 = [1, 2, 3];83 expect(actual2.sort()).toEqual(expected2);84 var actual3 = new CustomSet([3, 1, 2, 1]).toList();85 var expected3 = [1, 2, 3];86 expect(actual3.sort()).toEqual(expected3);87 });88 it('can test for union', function() {89 var actual = new CustomSet([1, 3]).union(new CustomSet([2]));90 var expected = new CustomSet([3, 2, 1]);91 expect(actual.eql(expected)).toBe(true);92 var actual2 = new CustomSet([1, 3]).union(new CustomSet([2, 3]));93 var expected2 = new CustomSet([3, 2, 1]);94 expect(actual2.eql(expected2)).toBe(true);95 var actual3 = new CustomSet([1, 3]).union(new CustomSet());96 var expected3 = new CustomSet([3, 1]);97 expect(actual3.eql(expected3)).toBe(true);98 var actual4 = new CustomSet().union(new CustomSet());99 var expected4 = new CustomSet();100 expect(actual4.eql(expected4)).toBe(true);101 });...
news.js
Source:news.js
1/* Dynamic Window Ajax Content */2"use strict";3var $actual2= null;4var obert2=false;5$(".last-news").click(function() {6 obre2($(this).attr('id'));7 $actual2=$(this);8});9 10function obre2(quin2){11 $.ajax({12 url: quin2,13 success: function(data) { 14 $('.news-content').html(data);15 $(".news-content").hide(0)16 $('.news-window').hide(0) 17 tanca2();18 canvia2(); 19 $("html, body").animate({ scrollTop: $('#news-show').offset().top - (200) }, 500, function(){20 $('.news-window').show(0);21 $('.news-window').css('height','0');22 $('.news-window').animate({height:760}, 1000,function(){23 $('.news-window').css('height','760');24 $(".news-content").fadeIn("slow");25 }); 26 });27 }28 });29}30/**/31function canvi2(quin2){32 var obert2=true;33 $.ajax({34 url: quin2,35 success: function(data) { 36 $('.news-content').html(data);37 tanca2();38 canvia2();39 $("html, body").animate({ scrollTop: $('#news-show').offset().top - (200) }, 500, function(){40 $('.news-window').show(0);41 $('.news-window').animate({height:760}, 1000,function(){42 $('.news-window').css('height','760');43 $(".news-content").fadeIn("slow");44 }); 45 });46 }47 });48}49/**/50function tanca2(){51 $(".close2-btn").click(function() {52 $(".news-window").slideUp("slow");53 $(".news-content").fadeOut("slow");54 $("html, body").animate({ scrollTop: $('#anchor01').offset().top }, 1000);55 obert2=false;56 });57}58function seguent(){59 if($actual2.next().hasClass('end')){60 $(".news-content").fadeOut("slow");61 $actual2=$($('.start').next());62 }else{63 $(".news-content").fadeOut("slow");64 $actual2=$($actual2.next());65 }66 if($actual2.hasClass('isotope-hidden')){67 seguent();68 }else{69 $(".news-content").fadeOut("slow");70 canvi2($actual2.attr('id'));71 }72}73function enrera(){74 if($actual2.prev().hasClass('start')){75 $(".news-content").fadeOut("slow");76 $actual2=$($('.end').prev());77 }else{78 $(".news-content").fadeOut("slow");79 $actual2=$($actual2.prev());80 }81 if($actual2.hasClass('isotope-hidden')){82 enrera();83 }else{84 $(".news-content").fadeOut("slow");85 canvi2($actual2.attr('id'));86 }87}88function canvia2(){89 $('.news-next').click(function() {90 seguent();91 });92 $('.news-prev').click(function() {93 enrera();94 });...
Using AI Code Generation
1import {actual2} from 'ng-mocks';2import {actual2} from 'ng-mocks';3import {actual2} from 'ng-mocks';4import {actual2} from 'ng-mocks';5import {actual2} from 'ng-mocks';6import {actual2} from 'ng-mocks';7import {actual2} from 'ng-mocks';8import {actual2} from 'ng-mocks';9import {actual2} from 'ng-mocks';10import {actual2} from 'ng-mocks';11import {actual2} from 'ng-mocks';12import {actual2} from 'ng-mocks';13import {actual2} from 'ng-mocks';14import {actual2} from 'ng-mocks';15import {actual2} from 'ng-mocks';16import {actual2} from 'ng-mocks';17import {actual2} from 'ng-mocks';18import {actual2} from 'ng-mocks';19import {actual2} from 'ng-mocks';20import {actual2} from 'ng
Using AI Code Generation
1import { actual2 } from 'ng-mocks';2describe('Component', () => {3 it('should work', () => {4 const fixture = MockRender(MyComponent);5 const actual = actual2(fixture);6 expect(actual).toBeInstanceOf(MyComponent);7 });8});9import { actual2 } from 'ng-mocks';10describe('Component', () => {11 it('should work', () => {12 const fixture = MockRender(MyComponent);13 const actual = actual2(fixture);14 expect(actual).toBeInstanceOf(MyComponent);15 });16});17import { actual2 } from 'ng-mocks';18describe('Component', () => {19 it('should work', () => {20 const fixture = MockRender(MyComponent);21 const actual = actual2(fixture);22 expect(actual).toBeInstanceOf(MyComponent);23 });24});25import { actual2 } from 'ng-mocks';26describe('Component', () => {27 it('should work', () => {28 const fixture = MockRender(MyComponent);29 const actual = actual2(fixture);30 expect(actual).toBeInstanceOf(MyComponent);31 });32});33import { actual2 } from 'ng-mocks';34describe('Component', () => {35 it('should work', () => {36 const fixture = MockRender(MyComponent);37 const actual = actual2(fixture);38 expect(actual).toBeInstanceOf(MyComponent);39 });40});41import { actual2 } from 'ng-mocks';42describe('Component', () => {43 it('should work', () => {44 const fixture = MockRender(MyComponent);45 const actual = actual2(fixture);46 expect(actual).toBeInstanceOf(MyComponent);47 });48});49import { actual2 } from 'ng-mocks';50describe('Component', () => {51 it('should work', () => {52 const fixture = MockRender(MyComponent);53 const actual = actual2(fixture);54 expect(actual).toBeInstanceOf(MyComponent);55 });56});57import { actual2 } from 'ng-mocks';58describe('Component', () => {59 it('should work', () => {60 const fixture = MockRender(MyComponent);61 const actual = actual2(fixture);62 expect(actual).toBeInstanceOf(MyComponent);63 });64});65import { actual2 } from 'ng-mocks';66describe('Component', () => {67 it('should work', () => {68 const fixture = MockRender(MyComponent);69 const actual = actual2(fixture);70 expect(actual).toBeInstanceOf(My
Using AI Code Generation
1import { actual2 } from 'ng-mocks';2describe('TestComponent', () => {3 it('should create', () => {4 const component = actual2(TestComponent);5 expect(component).toBeTruthy();6 });7});8import { actual2 } from 'ng-mocks';9describe('TestComponent2', () => {10 it('should create', () => {11 const component = actual2(TestComponent2);12 expect(component).toBeTruthy();13 });14});15import { actual2 } from 'ng-mocks';16describe('TestComponent3', () => {17 it('should create', () => {18 const component = actual2(TestComponent3);19 expect(component).toBeTruthy();20 });21});22import { actual2 } from 'ng-mocks';23describe('TestComponent4', () => {24 it('should create', () => {25 const component = actual2(TestComponent4);26 expect(component).toBeTruthy();27 });28});29import { actual2 } from 'ng-mocks';30describe('TestComponent5', () => {31 it('should create', () => {32 const component = actual2(TestComponent5);33 expect(component).toBeTruthy();34 });35});36import { actual2 } from 'ng-mocks';37describe('TestComponent6', () => {38 it('should create', () => {39 const component = actual2(TestComponent6);40 expect(component).toBeTruthy();41 });42});43import { actual2 } from 'ng-mocks';44describe('TestComponent7', () => {45 it('should create', () => {46 const component = actual2(TestComponent7);47 expect(component).toBeTruthy();48 });49});
Using AI Code Generation
1import { actual2 } from 'ng-mocks';2import { actual2 } from 'ng-mocks';3import { TestComponent } from './test.component';4describe('TestComponent', () => {5 let component: TestComponent;6 let fixture: ComponentFixture<TestComponent>;7 beforeEach(async(() => {8 TestBed.configureTestingModule({9 })10 .compileComponents();11 }));12 beforeEach(() => {13 fixture = TestBed.createComponent(TestComponent);14 component = fixture.componentInstance;15 fixture.detectChanges();16 });17 it('should get the actual instance of a component', () => {18 const actualComponent = actual2(component);19 expect(actualComponent).toBeTruthy();20 expect(actualComponent.add(1, 2)).toEqual(3);21 });22});23import { Component } from '@angular/core';24@Component({25})26export class TestComponent {27 add(first: number, second: number) {28 return first + second;29 }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!!