How to use expectThrow method in ng-mocks

Best JavaScript code snippet using ng-mocks

Braided.js

Source:Braided.js Github

copy

Full Screen

...54 })55 // Exercises use of openzeppelin-solidity/Owner56 context('ownership and permissions', () => {57 it('should not allow non-owner to set new owner', async () => {58 await expectThrow(braided.transferOwnership(rando, { from: rando }))59 })60 it('should allow owner to set new owner', async () => {61 await braided.transferOwnership(owner1, { from: owner0 })62 })63 it('should allow owner to set new owner', async () => {64 await braided.transferOwnership(owner2, { from: owner1 })65 })66 it('should allow owner to set new owner', async () => {67 await braided.transferOwnership(owner1, { from: owner2 })68 })69 })70 // Test linking multiple testnets together71 context('Link testnets', () => {72 it('should add strands', async () => {73 await braided.addStrand(mainnetID, braided.address, mainnetGenesis, 'Foundation', { from: owner1 });74 (await web3.eth.getBlock('latest')).number.should.eq(75 (await braided.getStrandCreationBlockNumber(mainnetID)).toNumber())76 await braided.addStrand(goerliID, braided.address, goerliGenesis, 'goerli', { from: owner1 });77 (await web3.eth.getBlock('latest')).number.should.eq(78 (await braided.getStrandCreationBlockNumber(goerliID)).toNumber())79 await braided.addStrand(ropstenID, braided.address, ropstenGenesis, 'Ropsten', { from: owner1 });80 (await web3.eth.getBlock('latest')).number.should.eq(81 (await braided.getStrandCreationBlockNumber(ropstenID)).toNumber())82 await braided.addStrand(kovanID, braided.address, kovanGenesis, 'Kovan', { from: owner1 });83 (await web3.eth.getBlock('latest')).number.should.eq(84 (await braided.getStrandCreationBlockNumber(kovanID)).toNumber())85 await braided.addStrand(rinkebyID, braided.address, rinkebyGenesis, 'Rinkeby', { from: owner1 });86 (await web3.eth.getBlock('latest')).number.should.eq(87 (await braided.getStrandCreationBlockNumber(rinkebyID)).toNumber())88 await braided.addStrand(classicID, braided.address, mainnetGenesis, 'Classic', { from: owner1 });89 (await web3.eth.getBlock('latest')).number.should.eq(90 (await braided.getStrandCreationBlockNumber(classicID)).toNumber())91 await braided.addStrand(classictestID, braided.address, goerliGenesis, 'Classic test', { from: owner1 });92 (await web3.eth.getBlock('latest')).number.should.eq(93 (await braided.getStrandCreationBlockNumber(classictestID)).toNumber());94 (await braided.getStrandCount()).toNumber().should.be.eq(7)95 })96 it('should not allow strand ID 0', async () => {97 await expectThrow(braided.addStrand(0, braided.address, zero, 'zero'))98 })99 it('should not allow non-owner to add strand', async () => {100 await expectThrow(braided.addStrand(7, braided.address, mainnetGenesis, 'unlucky', { from: agent1 }))101 })102 it('should fail to get strand ID by invalid index', async () => {103 await expectThrow(braided.getStrandID(7))104 await expectThrow(braided.getStrandID(8))105 })106 it('should get strand ID by zero-based index', async () => {107 (await braided.getStrandID(0)).toNumber().should.be.eq(mainnetID);108 (await braided.getStrandID(1)).toNumber().should.be.eq(goerliID);109 (await braided.getStrandID(2)).toNumber().should.be.eq(ropstenID);110 (await braided.getStrandID(3)).toNumber().should.be.eq(kovanID);111 (await braided.getStrandID(4)).toNumber().should.be.eq(rinkebyID);112 (await braided.getStrandID(5)).toNumber().should.be.eq(classicID);113 (await braided.getStrandID(6)).toNumber().should.be.eq(classictestID)114 })115 it('should get strand info per ID', async () => {116 (await braided.getStrandGenesisBlockHash(mainnetID)).should.be.eq(mainnetGenesis)117 String(await braided.getStrandDescription(ropstenID)).should.be.eq('Ropsten')118 String(await braided.getStrandContract(ropstenID)).should.be.eq(braided.address)119 await expectThrow(braided.getStrandGenesisBlockHash(33))120 await expectThrow(braided.getStrandDescription(83))121 })122 it('should not allow a duplicate strand with the same ID', async () => {123 await expectThrow(braided.addStrand(mainnetID, braided.address, zero, 'Dup', { from: owner1 }));124 // ensure unmodified125 (await braided.getStrandGenesisBlockHash(mainnetID)).should.be.eq(mainnetGenesis)126 })127 })128 context('Add agents', () => {129 it('should add strands', async () => {130 await braided.addAgent(agent1, mainnetID, { from: owner1 })131 await braided.addAgent(agent2, mainnetID, { from: owner1 })132 })133 it('should allow owner to add agents', async () => {134 await braided.addAgent(agent3, mainnetID, { from: owner1 })135 await braided.addAgent(agent4, mainnetID, { from: owner1 })136 await braided.addAgent(agent4, ropstenID, { from: owner1 })137 await braided.addAgent(agent4, classicID, { from: owner1 })138 })139 it('should not allow non-owner to add agent', async () => {140 await expectThrow(braided.addAgent(agent1, mainnetID, { from: owner2 }))141 })142 it('should allow owner to remove agent', async () => {143 await braided.removeAgent(agent2, mainnetID, { from: owner1 })144 })145 it('should allow owner to remove agent', async () => {146 await braided.removeAgent(agent3, mainnetID, { from: owner1 })147 })148 it('should not allow non-owner to remove agent', async () => {149 await expectThrow(braided.addAgent(agent1, mainnetID, { from: owner2 }))150 })151 })152 context('set and get hashes', () => {153 it('should allow agents to add hashes', async () => {154 await braided.addBlock(mainnetID, 1, mainnet1, { from: agent1 })155 await braided.addBlock(mainnetID, 2, mainnet2, { from: agent1 })156 await braided.addBlock(mainnetID, 3, mainnet3, { from: agent1 })157 await braided.addBlock(ropstenID, 1, ropsten1, { from: agent4 })158 await braided.addBlock(ropstenID, 2, ropsten2, { from: agent4 })159 await braided.addBlock(classicID, 1, mainnet1, { from: agent4 })160 // but not on an invalid strand161 await expectThrow(braided.addBlock(5, 1, mainnet1, { from: agent1 }))162 })163 it('should not allow non-agents to add hashes', async () => {164 await expectThrow(braided.addBlock(classicID, 2, mainnet2, { from: owner0 }))165 await expectThrow(braided.addBlock(classicID, 2, mainnet2, { from: owner2 }))166 await expectThrow(braided.addBlock(classicID, 2, mainnet2, { from: agent2 }))167 await expectThrow(braided.addBlock(classicID, 2, mainnet2, { from: agent3 }))168 await expectThrow(braided.addBlock(classicID, 2, mainnet2, { from: rando }))169 })170 it('should retrieve lowest block number in a strand', async () => {171 (await braided.getLowestBlockNumber(mainnetID)).toNumber().should.be.eq(1);172 (await braided.getLowestBlockNumber(ropstenID)).toNumber().should.be.eq(1);173 (await braided.getLowestBlockNumber(classicID)).toNumber().should.be.eq(1)174 await braided.addAgent(agent2, goerliID, { from: owner1 })175 await braided.addBlock(goerliID, 10, goerlia, { from: agent2 })176 await braided.addBlock(goerliID, 12, goerlic, { from: agent2 })177 await braided.addBlock(goerliID, 14, goerlie, { from: agent2 });178 (await braided.getLowestBlockNumber(goerliID)).toNumber().should.be.eq(10)179 })180 it('should retrieve highest block number in a strand', async () => {181 (await braided.getHighestBlockNumber(mainnetID)).toNumber().should.be.eq(3);182 (await braided.getHighestBlockNumber(ropstenID)).toNumber().should.be.eq(2);183 (await braided.getHighestBlockNumber(classicID)).toNumber().should.be.eq(1);184 (await braided.getHighestBlockNumber(goerliID)).toNumber().should.be.eq(14)185 })186 it('should not retrieve highest block number for invalid strands', async () => {187 await expectThrow(braided.getHighestBlockNumber(2))188 })189 it('should not retrieve highest block number for empty strands', async () => {190 await expectThrow(braided.getHighestBlockNumber(kovanID))191 })192 it('should retrieve hashes for specific block numbers', async () => {193 (await braided.getBlockHash(mainnetID, 1)).should.be.eq(mainnet1);194 (await braided.getBlockHash(mainnetID, 2)).should.be.eq(mainnet2);195 (await braided.getBlockHash(mainnetID, 3)).should.be.eq(mainnet3);196 (await braided.getBlockHash(ropstenID, 1)).should.be.eq(ropsten1);197 (await braided.getBlockHash(ropstenID, 2)).should.be.eq(ropsten2);198 (await braided.getBlockHash(classicID, 1)).should.be.eq(mainnet1)199 })200 it('should require increasing block numbers for any given strand', async () => {201 await braided.addBlock(mainnetID, 9, mainnet9, { from: agent1 })202 await expectThrow(braided.addBlock(mainnetID, 8, mainnet8, { from: agent1 }))203 })204 it('should not retrieve hashes for nonexistent block numbers', async () => {205 await expectThrow(braided.getBlockHash(mainnetID, 8))206 await expectThrow(braided.getBlockHash(mainnetID, 0))207 })208 it('should get previous block number', async () => {209 (await braided.getPreviousBlockNumber(mainnetID, 9)).toNumber().should.be.eq(3)210 })211 it('should get previous block', async () => {212 let block = await braided.getPreviousBlock(mainnetID, 9)213 block[0].toNumber().should.be.eq(3)214 block[1].should.be.eq(mainnet3)215 })216 it('should fail to get previous block number for unrecorded blocks', async () => {217 await expectThrow(braided.getPreviousBlockNumber(mainnetID, 8))218 await expectThrow(braided.getPreviousBlockNumber(mainnetID, 0))219 await expectThrow(braided.getPreviousBlockNumber(mainnetID, 11))220 })221 it('should fail to get previous block for unrecorded blocks', async () => {222 await expectThrow(braided.getPreviousBlock(mainnetID, 8))223 await expectThrow(braided.getPreviousBlock(mainnetID, 0))224 await expectThrow(braided.getPreviousBlock(mainnetID, 11))225 })226 it('should get the number of blocks recorded for a chain', async () => {227 // invalid strandID228 await expectThrow(braided.getBlockCount(2));229 (await braided.getBlockCount(mainnetID)).toNumber().should.be.eq(4);230 (await braided.getBlockCount(goerliID)).toNumber().should.be.eq(3);231 (await braided.getBlockCount(ropstenID)).toNumber().should.be.eq(2);232 (await braided.getBlockCount(rinkebyID)).toNumber().should.be.eq(0);233 (await braided.getBlockCount(kovanID)).toNumber().should.be.eq(0);234 (await braided.getBlockCount(classicID)).toNumber().should.be.eq(1);235 (await braided.getBlockCount(classictestID)).toNumber().should.be.eq(0)236 })237 it('should emit an event when adding a block', async () => {238 let tx = await braided.addBlock(mainnetID, 10, mainneta, { from: agent1 })239 tx.logs[0].event.should.be.equal('BlockAdded')240 tx.logs[0].args.strandID.toNumber().should.be.eq(mainnetID)241 tx.logs[0].args.blockNumber.toNumber().should.be.eq(10)242 tx.logs[0].args.blockHash.should.be.eq(mainneta)...

Full Screen

Full Screen

ministroVerifierRegistry.js

Source:ministroVerifierRegistry.js Github

copy

Full Screen

1import BigNumber from 'bignumber.js';2import ministroExecute from 'ministro-tool';3import { formatVerifier, areAddressesEqual } from '../helpers/functions';4function MinistroContract() {5 const app = {};6 /* eslint-disable-next-line */7 app.__proto__ = ministroExecute();8 app.create = async (name, location, txAttr, expectThrow) => {9 const txAttrLocal = app.getTxAttr(txAttr);10 const action = () => app.instance.create(name, location, txAttrLocal);11 let prevVerifierStatus;12 if (!expectThrow) {13 prevVerifierStatus = await app.isRegisteredVerifier(txAttrLocal.from);14 }15 const results = await app.executeAction(action, txAttrLocal, 1, 'LogVerifierRegistered', expectThrow);16 if (!expectThrow) {17 assert.exists(results.LogVerifierRegistered, 'missing LogVerifierRegistered event');18 const [logVerifierRegistered] = results.LogVerifierRegistered;19 assert(areAddressesEqual(logVerifierRegistered.id, txAttrLocal.from), 'invalid verifier address');20 assert.strictEqual(logVerifierRegistered.name.toLowerCase(), name.toLowerCase(), 'invalid name');21 assert.strictEqual(logVerifierRegistered.location, location, 'invalid location');22 assert(!logVerifierRegistered.active, 'new verifier should be not active');23 assert(!logVerifierRegistered.enabled, 'new verifier should be disabled');24 assert.strictEqual(logVerifierRegistered.balance.toString(), '0', 'new verifier should have no balance');25 const verifier = await app.verifiers(txAttrLocal.from);26 assert(areAddressesEqual(logVerifierRegistered.id, verifier.id), 'should be saved onchain');27 assert(!verifier.active, 'should be active after creation onchain');28 assert(!verifier.enabled, 'should be disabled after creation onchain');29 assert.isFalse(prevVerifierStatus, 'should be NOT recognizable as verifier before registration');30 assert.isTrue(await app.isRegisteredVerifier(verifier.id), 'should be recognizable as verifier');31 }32 return results;33 };34 app.update = async (name, location, txAttr, expectThrow) => {35 const txAttrLocal = app.getTxAttr(txAttr);36 const action = () => app.instance.update(name, location, txAttrLocal);37 const results = await app.executeAction(action, txAttrLocal, 1, 'LogVerifierUpdated', expectThrow);38 if (!expectThrow) {39 assert.exists(results.LogVerifierUpdated, 'missing LogVerifierUpdated event');40 const [logVerifierUpdated] = results.LogVerifierUpdated;41 assert(areAddressesEqual(logVerifierUpdated.id, txAttrLocal.from), 'invalid verifier address');42 assert.strictEqual(logVerifierUpdated.name.toLowerCase(), name.toLowerCase(), 'invalid name');43 assert.strictEqual(logVerifierUpdated.location, location, 'invalid location');44 const verifier = await app.verifiers(txAttrLocal.from);45 assert(areAddressesEqual(verifier.id, logVerifierUpdated.id), 'should be saved onchain');46 assert.strictEqual(verifier.name.toLowerCase(), name.toLowerCase(), 'invalid name');47 assert.strictEqual(verifier.location, location, 'invalid location');48 }49 return results;50 };51 app.updateActiveStatus = async (active, txAttr, expectThrow) => {52 const txAttrLocal = app.getTxAttr(txAttr);53 const action = () => app.instance.updateActiveStatus(active, txAttrLocal);54 const results = await app.executeAction(action, txAttrLocal, null, 'LogUpdateActiveStatus', expectThrow);55 if (!expectThrow) {56 assert.exists(results.LogBalancePerShard, 'missing LogBalancePerShard event - balances should be updated');57 assert.exists(results.LogUpdateActiveStatus, 'missing LogUpdateActiveStatus event');58 const [logUpdateActiveStatus] = results.LogUpdateActiveStatus;59 assert(areAddressesEqual(logUpdateActiveStatus.verifier, txAttrLocal.from), 'invalid verifier');60 assert.strictEqual(logUpdateActiveStatus.active, active, 'invalid active status');61 const savedVerifier = await app.verifiers(txAttrLocal.from);62 assert(areAddressesEqual(savedVerifier.id, txAttrLocal.from), 'should be saved onchain');63 assert.strictEqual(savedVerifier.active, active, 'invalid active status');64 }65 return results;66 };67 app.updateEnabledStatus = async (verifier, enabled, txAttr, expectThrow) => {68 const txAttrLocal = app.getTxAttr(txAttr);69 const action = () => app.instance.updateEnabledStatus(verifier, enabled, txAttrLocal);70 const results = await app.executeAction(action, txAttrLocal, null, 'LogUpdateEnabledStatus', expectThrow);71 if (!expectThrow) {72 assert.exists(results.LogBalancePerShard, 'missing LogBalancePerShard event - balances should be updated');73 assert.exists(results.LogUpdateEnabledStatus, 'missing LogUpdateEnabledStatus event');74 const [logUpdateEnabledStatus] = results.LogUpdateEnabledStatus;75 assert(areAddressesEqual(logUpdateEnabledStatus.executor, txAttrLocal.from), 'invalid executor');76 assert(areAddressesEqual(logUpdateEnabledStatus.verifier, verifier), 'invalid verifier');77 assert.strictEqual(logUpdateEnabledStatus.enabled, enabled, 'invalid enabled status');78 const savedVerifier = await app.verifiers(verifier);79 assert(areAddressesEqual(savedVerifier.id, verifier), 'should be saved onchain');80 assert.strictEqual(savedVerifier.enabled, enabled, 'invalid enabled status');81 if (!enabled) {82 assert(!savedVerifier.active, 'invalid active status');83 }84 }85 return results;86 };87 app.updateVerifiersPerShard = async (verifiersPerShard, txAttr, expectThrow) => {88 const txAttrLocal = app.getTxAttr(txAttr);89 const action = () => app.instance.updateVerifiersPerShard(verifiersPerShard, txAttrLocal);90 const results = await app.executeAction(action, txAttrLocal, null, null, expectThrow);91 if (!expectThrow) {92 assert.strictEqual((await app.verifiersPerShard()).toString(), verifiersPerShard.toString(), 'should be saved onchain');93 }94 return results;95 };96 app.increaseShardBalance = async (verifier, amount, txAttr, expectThrow) => {97 const txAttrLocal = app.getTxAttr(txAttr);98 const { shard } = await app.verifiers(verifier);99 let prevShardBalance;100 if (!expectThrow) {101 prevShardBalance = await app.balancesPerShard(shard.toString());102 }103 const action = () => app.instance.increaseShardBalance(verifier, amount, txAttrLocal);104 const results = await app.executeAction(action, txAttrLocal, null, null, expectThrow);105 if (!expectThrow) {106 const shardBalance = await app.balancesPerShard(shard.toString());107 assert(BigNumber(prevShardBalance).plus(amount).eq(shardBalance), 'invalid shard balance');108 }109 return results;110 };111 app.decreaseShardBalance = async (verifier, amount, txAttr, expectThrow) => {112 const txAttrLocal = app.getTxAttr(txAttr);113 const { shard } = await app.verifiers(verifier);114 let prevShardBalance;115 if (!expectThrow) {116 prevShardBalance = await app.balancesPerShard(shard.toString());117 }118 const action = () => app.instance.decreaseShardBalance(verifier, amount, txAttrLocal);119 const results = await app.executeAction(action, txAttrLocal, null, null, expectThrow);120 if (!expectThrow) {121 const shardBalance = await app.balancesPerShard(shard.toString());122 assert(BigNumber(prevShardBalance).minus(amount).eq(shardBalance), 'invalid shard balance');123 }124 return results;125 };126 app.verifiers = async address => formatVerifier(await app.instance.verifiers.call(address));127 app.uniqueNames = async hash => app.instance.uniqueNames.call(hash);128 app.balancesPerShard = async shard => app.instance.balancesPerShard.call(shard);129 app.addresses = async i => app.instance.addresses.call(i);130 app.verifiersPerShard = async () => app.instance.verifiersPerShard.call();131 app.isRegisteredVerifier = async address => app.instance.isRegisteredVerifier.call(address);132 app.getNumberOfVerifiers = async () => app.instance.getNumberOfVerifiers.call();133 return app;134}...

Full Screen

Full Screen

regress-465980-02.js

Source:regress-465980-02.js Github

copy

Full Screen

1// |reftest| skip -- slow2/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */3/* This Source Code Form is subject to the terms of the Mozilla Public4 * License, v. 2.0. If a copy of the MPL was not distributed with this5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */6//-----------------------------------------------------------------------------7var BUGNUMBER = 465980;8var summary = 'Do not crash @ InitArrayElements';9var actual = '';10var expect = '';11//-----------------------------------------------------------------------------12test();13//-----------------------------------------------------------------------------14function test()15{16 enterFunc ('test');17 printBugNumber(BUGNUMBER);18 printStatus (summary);19 function describe(name, startLength, pushArgs, expectThrow, expectLength)20 {21 return name + "(" + startLength + ", " +22 "[" + pushArgs.join(", ") + "], " +23 expectThrow + ", " +24 expectLength + ")";25 }26 var push = Array.prototype.push;27 var unshift = Array.prototype.unshift;28 function testArrayPush(startLength, pushArgs, expectThrow, expectLength)29 {30 print("running testArrayPush(" +31 startLength + ", " +32 "[" + pushArgs.join(", ") + "], " +33 expectThrow + ", " +34 expectLength + ")...");35 var a = new Array(startLength);36 try37 {38 push.apply(a, pushArgs);39 if (expectThrow)40 {41 throw "expected to throw for " +42 describe("testArrayPush", startLength, pushArgs, expectThrow,43 expectLength);44 }45 }46 catch (e)47 {48 if (!(e instanceof RangeError))49 {50 throw "unexpected exception type thrown: " + e + " for " +51 describe("testArrayPush", startLength, pushArgs, expectThrow,52 expectLength);53 }54 if (!expectThrow)55 {56 throw "unexpected exception " + e + " for " +57 describe("testArrayPush", startLength, pushArgs, expectThrow,58 expectLength);59 }60 }61 if (a.length !== expectLength)62 {63 throw "unexpected modified-array length for " +64 describe("testArrayPush", startLength, pushArgs, expectThrow,65 expectLength);66 }67 for (var i = 0, sz = pushArgs.length; i < sz; i++)68 {69 var index = i + startLength;70 if (a[index] !== pushArgs[i])71 {72 throw "unexpected value " + a[index] +73 " at index " + index + " (" + i + ") during " +74 describe("testArrayPush", startLength, pushArgs, expectThrow,75 expectLength) + ", expected " + pushArgs[i];76 }77 }78 }79 function testArrayUnshift(startLength, unshiftArgs, expectThrow, expectLength)80 {81 print("running testArrayUnshift(" +82 startLength + ", " +83 "[" + unshiftArgs.join(", ") + "], " +84 expectThrow + ", " +85 expectLength + ")...");86 var a = new Array(startLength);87 try88 {89 unshift.apply(a, unshiftArgs);90 if (expectThrow)91 {92 throw "expected to throw for " +93 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,94 expectLength);95 }96 }97 catch (e)98 {99 if (!(e instanceof RangeError))100 {101 throw "unexpected exception type thrown: " + e + " for " +102 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,103 expectLength);104 }105 if (!expectThrow)106 {107 throw "unexpected exception " + e + " for " +108 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,109 expectLength);110 }111 }112 if (a.length !== expectLength)113 {114 throw "unexpected modified-array length for " +115 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,116 expectLength);117 }118 for (var i = 0, sz = unshiftArgs.length; i < sz; i++)119 {120 if (a[i] !== unshiftArgs[i])121 {122 throw "unexpected value at index " + i + " during " +123 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,124 expectLength);125 }126 }127 }128 var failed = true;129 try130 {131 var foo = "foo", bar = "bar", baz = "baz";132 testArrayPush(4294967294, [foo], false, 4294967295);133 testArrayPush(4294967294, [foo, bar], true, 4294967295);134 testArrayPush(4294967294, [foo, bar, baz], true, 4294967295);135 testArrayPush(4294967295, [foo], true, 4294967295);136 testArrayPush(4294967295, [foo, bar], true, 4294967295);137 testArrayPush(4294967295, [foo, bar, baz], true, 4294967295);138 testArrayUnshift(4294967294, [foo], false, 4294967295);139 testArrayUnshift(4294967294, [foo, bar], true, 4294967294);140 testArrayUnshift(4294967294, [foo, bar, baz], true, 4294967294);141 testArrayUnshift(4294967295, [foo], true, 4294967295);142 testArrayUnshift(4294967295, [foo, bar], true, 4294967295);143 testArrayUnshift(4294967295, [foo, bar, baz], true, 4294967295);144 }145 catch (e)146 {147 actual = e + '';148 }149 reportCompare(expect, actual, summary);150 exitFunc ('test');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { expectThrow } from 'ng-mocks';2describe('MyService', () => {3 let service: MyService;4 beforeEach(() => {5 TestBed.configureTestingModule({6 });7 });8 beforeEach(inject([MyService], (myService: MyService) => {9 service = myService;10 }));11 it('should throw an error', () => {12 expectThrow(13 () => service.throwError(),14 );15 });16});17import { expectSetInput } from 'ng-mocks';18describe('MyComponent', () => {19 let component: MyComponent;20 beforeEach(() => {21 TestBed.configureTestingModule({22 });23 });24 beforeEach(() => {25 component = TestBed.createComponent(MyComponent).componentInstance;26 });27 it('should set an input', () => {28 expectSetInput(29 );30 });31});32import { expectSetInputs } from 'ng-mocks';33describe('MyComponent', () => {34 let component: MyComponent;35 beforeEach(() => {36 TestBed.configureTestingModule({37 });38 });39 beforeEach(() => {40 component = TestBed.createComponent(MyComponent).componentInstance;41 });42 it('should set multiple inputs', () => {43 expectSetInputs(44 {45 },46 );47 });48});49import { expectSetOutput } from 'ng-mocks';50describe('MyComponent', () => {51 let component: MyComponent;52 beforeEach(() => {53 TestBed.configureTestingModule({54 });55 });56 beforeEach(() => {57 component = TestBed.createComponent(MyComponent).componentInstance;58 });59 it('should set an output', () => {60 expectSetOutput(61 );62 });63});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { expectThrow } from 'ng-mocks';2import { MyService } from './my-service';3describe('MyService', () => {4 let service: MyService;5 beforeEach(() => {6 service = new MyService();7 });8 it('should throw an error', () => {9 expectThrow(() => service.doSomething(), 'Error');10 });11});12import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';13import { AppModule } from './app.module';14import { MyService } from './my-service';15beforeEach(() => MockBuilder(MyService, AppModule));16it('mocks service', () => {17 const service = MockRender(MyService);18 expect(service).toBeDefined();19 expect(ngMocks.formatText(service)).toEqual('');20});21it('mocks service with a value', () => {22 const service = MockRender(MyService).point.componentInstance;23 service.value = 'test';24 expect(ngMocks.formatText(service)).toEqual('test');25});26import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';27import { AppModule } from './app.module';28import { MyComponent } from './my-component';29beforeEach(() => MockBuilder(MyComponent, AppModule));30it('mocks component', () => {31 const fixture = MockRender(MyComponent);32 expect(fixture.point.componentInstance).toBeDefined();33 expect(ngMocks.formatText(fixture)).toEqual('');34});35it('mocks component with a value', () => {36 const fixture = MockRender(MyComponent);37 fixture.point.componentInstance.value = 'test';38 expect(ngMocks.formatText(fixture)).toEqual('test');39});40import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';41import { AppModule } from './app.module';42import { MyDirective } from './my-directive';43beforeEach(() => MockBuilder(MyDirective, AppModule));44it('mocks directive', () => {45 const fixture = MockRender(MyDirective);46 expect(fixture.point.componentInstance).toBeDefined();47 expect(ngMocks.formatText(fixture)).toEqual('');48});49it('mocks directive with a value', () => {50 const fixture = MockRender(My

Full Screen

Using AI Code Generation

copy

Full Screen

1import { expectThrow } from 'ng-mocks';2import { async } from 'ng-mocks';3import { TestBed } from 'ng-mocks';4import { MockBuilder } from 'ng-mocks';5import { MockRender } from 'ng-mocks';6import { MockInstance } from 'ng-mocks';7import { MockProvider } from 'ng-mocks';8import { MockService } from 'ng-mocks';9import { MockDirective } from 'ng-mocks';10import { MockComponent } from 'ng-mocks';11import { MockPipe } from 'ng-mocks';12import { MockRender } from 'ng-mocks';13import { MockRender } from 'ng-mocks';14import { MockRender } from 'ng-mocks';15import { MockRender } from 'ng-mocks';16import { MockRender } from 'ng-mocks';17import { MockRender } from 'ng-mocks';18import { MockRender } from 'ng-mocks';19import { MockRender } from 'ng-mocks';20import { MockRender } from 'ng-mocks';21import { MockRender } from 'ng-mocks';22import { MockRender } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1const ngMocks = require('ng-mocks');2const { expectThrow } = ngMocks.default;3const chai = require('chai');4const { expectThrow } = require('ng-mocks/dist/lib/test');5const ngMocks = require('ng-mocks');6const { expectThrow } = ngMocks.default;7const chai = require('chai');8const { expectThrow } = require('ng-mocks/dist/lib/test');9const chai = require('chai');10const { expectThrow } = require('ng-mocks/dist/lib/test');11describe('expectThrow', () => {12 it('should throw an error if the function does not throw an error', () => {13 expectThrow(() => {14 return 'Hello world';15 }, 'Expected function to throw an error');16 });17});18const ngMocks = require('ng-mocks');19const { expectThrow } = ngMocks.default;20const chai = require('chai');21const { expectThrow } = require('ng-mocks/dist/lib/test');22describe('expectThrow', () => {23 it('should throw an error if the function does not throw an error', () => {24 expectThrow(() => {25 return 'Hello world';26 }, 'Expected function to throw an error');27 });28 it('should throw an error if the function throws an error with a different message', () => {29 expectThrow(() => {30 throw new Error('Hello world');31 }, 'Expected function to throw an error with message "Hello world"');32 });33 it('should not throw an error if the function throws an error with the same message', () => {34 expectThrow(() => {35 throw new Error('Hello world');36 }, 'Hello world');37 });38});

Full Screen

Using AI Code Generation

copy

Full Screen

1import {expectThrow} from 'ng-mocks';2import {spyOnProperty} from 'ng-mocks';3describe('Component: MyComponent', () => {4 let component: MyComponent;5 let fixture: ComponentFixture<MyComponent>;6 let spy: jasmine.Spy;7 beforeEach(async(() => {8 TestBed.configureTestingModule({9 {provide: MyService, useClass: MyServiceStub},10 })11 .compileComponents()12 .then(() => {13 fixture = TestBed.createComponent(MyComponent);14 component = fixture.componentInstance;15 fixture.detectChanges();16 });17 }));18 it('should create', () => {19 expect(component).toBeTruthy();20 });21 it('should call doSomething() and set doSomethingCalled to true', () => {22 spy = spyOn(component, 'doSomething').and.callThrough();23 component.doSomething();24 expect(component.doSomethingCalled).toBe(true);25 expect(spy).toHaveBeenCalled();26 });27 it('should call doSomething() and set doSomethingCalled to true', () => {28 spy = spyOn(component, 'doSomething').and.callThrough();29 component.doSomething();30 expect(component.doSomethingCalled).toBe(true);31 expect(spy).toHaveBeenCalled();32 });33 it('should call doSomethingElse() and set doSomethingElseCalled to true', () => {34 spy = spyOn(component, 'doSomethingElse').and.callThrough();35 component.doSomethingElse();36 expect(component.doSomethingElseCalled).toBe(true);37 expect(spy).toHaveBeenCalled();38 });39 it('should call doSomethingElse() and set doSomethingElseCalled to true', () => {40 spy = spyOn(component, 'doSomethingElse').and.callThrough();41 component.doSomethingElse();42 expect(component.doSomethingElseCalled).toBe(true);43 expect(spy).toHaveBeenCalled();44 });45 it('should call doSomethingElse() and set doSomethingElseCalled to true', () => {46 spy = spyOn(component, 'doSomethingElse').and.callThrough();47 component.doSomethingElse();48 expect(component.doSomethingElseCalled).toBe(true);49 expect(spy).toHaveBeenCalled();50 });51 it('should call doSomethingElse() and set doSomethingElseCalled to true', () => {52 spy = spyOn(component, 'doSomethingElse').and.callThrough();53 component.doSomethingElse();

Full Screen

Using AI Code Generation

copy

Full Screen

1const ngMocks = require('ng-mocks');2const expectThrow = ngMocks.expectThrow;3it('should throw', () => {4 expectThrow(() => {5 throw new Error('MyError');6 }, 'MyError');7});8const ngMocks = require('ng-mocks');9it('should resolve', () => {10 const observable = new Observable((observer) => {11 observer.next(1);12 observer.complete();13 });14 let result;15 observable.subscribe((value) => {16 result = value;17 });18 ngMocks.flush();19 expect(result).toEqual(1);20});21const ngMocks = require('ng-mocks');22it('should resolve', () => {23 const httpClient = new HttpClient();24 let result;25 httpClient.get('/data').subscribe((value) => {26 result = value;27 });28 ngMocks.flush();29 expect(result).toEqual(1);30});31const ngMocks = require('ng-mocks');32it('should resolve', () => {33 const router = new Router();34 let result;35 router.navigate(['/']).subscribe((value) => {36 result = value;37 });38 ngMocks.flush();39 expect(result).toEqual(1);40});41const ngMocks = require('ng-mocks');42it('should resolve', () => {43 const service = new MyService();44 let result;45 service.get().subscribe((value) => {46 result = value;47 });48 ngMocks.flush();

Full Screen

Using AI Code Generation

copy

Full Screen

1import {expectThrow} from 'ng-mocks';2import {expectAsyncThrow} from 'ng-mocks';3describe('Foo', () => {4 it('should throw an error', () => {5 expectThrow(() => {6 throw new Error('foo');7 }, Error, 'foo');8 });9 it('should throw an error async', async () => {10 await expectAsyncThrow(async () => {11 throw new Error('foo');12 }, Error, 'foo');13 });14});15import {mockNgRef} from 'ng-mocks';16describe('Foo', () => {17 it('should mock a service', () => {18 const serviceMock = mockNgRef(Service);19 expect(serviceMock).toBeDefined();20 });21});22import {mockNgRefInScope} from 'ng-mocks';23describe('Foo', () => {24 it('should mock a service', () => {25 const serviceMock = mockNgRefInScope(Service);26 expect(serviceMock).toBeDefined();27 });28});

Full Screen

Using AI Code Generation

copy

Full Screen

1const ngMocks = require('ng-mocks');2const expectThrow = ngMocks.expectThrow;3const expect = ngMocks.expect;4const chai = require('chai');5const expectThrow = chai.expectThrow;6const expect = chai.expect;7const chai = require('chai');8const chaiAsPromised = require('chai-as-promised');9chai.use(chaiAsPromised);10const expectThrow = chai.expectThrow;11const expect = chai.expect;12const ngMocks = require('ng-mocks');13describe('Example', () => {14 it('should throw an error', () => {15 expectThrow(() => {16 throw new Error('error');17 }, 'error');18 });19 it('should throw an error', () => {20 expectThrow(() => {21 throw new Error('error');22 }, /error/);23 });24 it('should throw an error', () => {25 expectThrow(() => {26 throw new Error('error');27 }, Error);28 });29 it('should throw an error', () => {30 expectThrow(() => {31 throw new Error('error');32 }, Error, 'error');33 });34 it('should throw an error', () => {35 expectThrow(() => {36 throw new Error('error');37 }, Error, /error/);38 });39 it('should throw an error', () => {40 expectThrow(() => {41 throw new Error('error');42 }, Error, (error) => {43 return error.message === 'error';44 });45 });46});47const ngMocks = require('ng-mocks');48describe('Example', () => {49 it('should not throw an error', () => {50 expect(() => {51 }).not.toThrow();52 });53 it('should not throw an error', () => {54 expect(() => {55 }).not.toThrowError();56 });57 it('should not throw an error', () => {58 expect(() => {59 }).not.toThrowError('error');60 });61 it('should not throw an error', () => {62 expect(() => {63 }).not.to

Full Screen

Using AI Code Generation

copy

Full Screen

1import { expectThrow } from 'ng-mocks';2import { PageObject } from 'ng-mocks';3import { MockComponent } from 'ng-mocks';4import { MockModule } from 'ng-mocks';5import { MockPipe } from 'ng-mocks';6import { MockRender } from 'ng-mocks';7import { MockService } from 'ng-mocks';8import { MockDirective } from 'ng-mocks';9import { MockProvider } from 'ng-mocks';10import { MockBuilder } from 'ng-mocks';11import { MockInstance } from 'ng-mocks';12import { MockReset } from 'ng-mocks';13import { MockRenderOptions } from 'ng-mocks';14import { MockRenderResult } from 'ng-mocks';15import { MockRenderComponent } from 'ng-mocks';16import { MockRenderDirective } from 'ng-mocks';17import { MockRenderPipe } from 'ng-mocks';18import { MockRenderService } from 'ng-mocks';19import { MockRenderModule } from 'ng-mocks';20import { MockRenderComponentType } from 'ng-mocks';21import { MockRenderDirectiveType } from 'ng-mocks';22import { MockRenderPipeType } from 'ng-mocks';23import { MockRenderServiceType } from 'ng-mocks';24import { MockRenderModuleType } from 'ng-mocks';25import { MockRenderComponentTypeOptions } from 'ng-mocks';26import { MockRenderDirectiveTypeOptions } from 'ng-mocks';27import { MockRenderPipeTypeOptions } from 'ng-mocks';28import { MockRenderServiceTypeOptions } from 'ng-mocks';29import { MockRenderModuleTypeOptions } from 'ng-mocks';30import { MockRenderComponentTypeResult } from 'ng-mocks';31import { MockRenderDirectiveTypeResult } from 'ng-mocks';32import { MockRenderPipeTypeResult } from 'ng-mocks';33import { MockRenderServiceTypeResult } from 'ng-mocks';34import { MockRenderModuleTypeResult } from 'ng-mocks';35import { MockRenderComponentOptions } from 'ng-mocks';36import { MockRenderDirectiveOptions } from 'ng-mocks';37import { MockRenderPipeOptions } from 'ng-mocks';38import { MockRenderServiceOptions } from 'ng-mocks';39import { MockRenderModuleOptions } from 'ng-mocks';40import { MockRenderComponentResult } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import {expectThrow} from 'ng-mocks';2describe('test', () => {3 it('should throw', () => {4 expectThrow(() => {5 });6 });7});8import {expectSingle} from 'ng-mocks';9describe('test', () => {10 it('should throw', () => {11 expectSingle('my-component');12 });13});14import {findInstance} from 'ng-mocks';15describe('test', () => {16 it('should throw', () => {17 findInstance('my-component');18 });19});20import {findInstances} from 'ng-mocks';21describe('test', () => {22 it('should throw', () => {23 findInstances('my-component');24 });25});

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 ng-mocks 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