How to use expectedEntity method in stryker-parent

Best JavaScript code snippet using stryker-parent

EntityRepository.test.js

Source:EntityRepository.test.js Github

copy

Full Screen

1process.env.NODE_ENV = 'test';2const knex = require('knex');3const KnexMock = require('mock-knex');4const EntityRepository = require('./EntityRepository');5describe('Test suit for entityRepository', () => {6 const db = knex({client: 'pg'});7 let entityRepository = null;8 let knexTracker = null;9 beforeAll(() => {10 KnexMock.mock(db);11 entityRepository = new EntityRepository({12 entityName: 'Entity',13 db,14 logError: console.error15 });16 });17 beforeEach(() => {18 knexTracker = KnexMock.getTracker();19 knexTracker.install();20 });21 describe('getAll method', () => {22 it('get an array of objects', async () => {23 const expectedEntity = [{object: 1}, {object: 2}];24 knexTracker.on('query', (query, step) => {25 expect(query.method).toBe('select');26 query.response(expectedEntity);27 });28 const actualEntity = await entityRepository.getAll();29 expect(actualEntity).toEqual(expectedEntity);30 });31 it('handles errors when they arise (no leak)', async () => {32 let actualEntity;33 let expectedEntity;34 try {35 expectedEntity = new Error('Arbitrary Error');36 knexTracker.on('query', (query, step) => {37 expect(query.method).toBe('select');38 query.reject(expectedEntity);39 });40 actualEntity = await entityRepository.getAll();41 return actualEntity;42 }43 catch (error) {44 expect(error.message).toEqual('Error at DB');45 }46 });47 });48 49 describe('getById method', () => {50 it('get a specific entity based on id', async () => {51 const expectedEntity = [{object: 1}];52 knexTracker.on('query', (query, step) => {53 expect(query.method).toBe('select');54 query.response(expectedEntity);55 });56 const actualEntity = await entityRepository.getById(1);57 expect(actualEntity).toEqual(expectedEntity[0]);58 });59 it('handles errors when they arise (no leak)', async () => {60 let actualEntity;61 let expectedEntity;62 try {63 expectedEntity = new Error('Error at DB');64 knexTracker.on('query', (query, step) => {65 expect(query.method).toBe('select');66 query.reject(expectedEntity);67 });68 actualEntity = await entityRepository.getById(1);69 }70 catch (error) {71 expect(error.message).toEqual('Error at DB');72 }73 });74 });75 describe('getByEmail method', () => {76 it('get a specific entity based on email', async () => {77 const expectedEntity = [{object: 1}];78 knexTracker.on('query', (query, step) => {79 expect(query.method).toBe('select');80 query.response(expectedEntity);81 });82 const actualEntity = await entityRepository.getByEmail('chuck@gmail.com');83 expect(actualEntity).toEqual(expectedEntity[0]);84 });85 it('handles errors when they arise (no leak)', async () => {86 let actualEntity;87 let expectedEntity;88 try {89 expectedEntity = new Error('Error at DB');90 knexTracker.on('query', (query, step) => {91 expect(query.method).toBe('select');92 query.reject(expectedEntity);93 });94 actualEntity = await entityRepository.getByEmail('chuck@gmail.com');95 }96 catch (error) {97 expect(error.message).toEqual('Error at DB');98 }99 });100 });101 describe('getByIdentifier method', () => {102 it('get a single object', async () => {103 const expectedEntity = {object: 1};104 knexTracker.on('query', (query, step) => {105 expect(query.method).toBe('select');106 query.response([expectedEntity]);107 });108 const actualEntity = await entityRepository.getByIdentifier('chuckhagy@gmail.com', 'email');109 expect(actualEntity).toEqual(expectedEntity);110 });111 it('handles errors when they arise (no leak)', async () => {112 let actualEntity;113 let expectedEntity;114 try {115 expectedEntity = new Error('Error at DB');116 knexTracker.on('query', (query, step) => {117 expect(query.method).toBe('select');118 query.reject(expectedEntity);119 });120 actualEntity = await entityRepository.getByIdentifier(1, 'email');121 }122 catch (error) {123 expect(error.message).toEqual('Error at DB');124 }125 });126 });127 describe('getCollectionByIdentifier method', () => {128 it('get a single object', async () => {129 const expectedEntity = [{object: 1}, {object: 2}];130 knexTracker.on('query', (query, step) => {131 expect(query.method).toBe('select');132 query.response(expectedEntity);133 });134 const actualEntity = await entityRepository.getCollectionByIdentifier(1, 'user_id');135 expect(actualEntity).toEqual(expectedEntity);136 });137 it('handles errors when they arise (no leak)', async () => {138 let actualEntity;139 let expectedEntity;140 try {141 expectedEntity = new Error('Error at DB');142 knexTracker.on('query', (query, step) => {143 expect(query.method).toBe('select');144 query.reject(expectedEntity);145 });146 actualEntity = await entityRepository.getCollectionByIdentifier(1, 'user_id');147 }148 catch (error) {149 expect(error.message).toEqual('Error at DB');150 }151 });152 });153 describe('getTagsByComponent method', () => {154 it('get array of tags for a given component', async () => {155 const expectedEntity = [{object: 1}, {object: 2}];156 knexTracker.on('query', (query, step) => {157 expect(query.method).toBe('select');158 query.response(expectedEntity);159 });160 const actualEntity = await entityRepository.getTagsByComponent(1);161 expect(actualEntity).toEqual(expectedEntity);162 });163 it('handles errors when they arise (no leak)', async () => {164 let actualEntity;165 let expectedEntity;166 try {167 expectedEntity = new Error('Error at DB');168 knexTracker.on('query', (query, step) => {169 expect(query.method).toBe('select');170 query.reject(expectedEntity);171 });172 actualEntity = await entityRepository.getTagsByComponent(1);173 }174 catch (error) {175 expect(error.message).toEqual('Error at DB');176 }177 });178 });179 describe('getFollowers method', () => {180 it('get an array of followers', async () => {181 const expectedEntity = [{object: 1}, {object: 2}];182 knexTracker.on('query', (query, step) => {183 expect(query.method).toBe('select');184 query.response(expectedEntity);185 });186 const actualEntity = await entityRepository.getFollowers(1);187 expect(actualEntity).toEqual(expectedEntity);188 });189 it('handles errors when they arise (no leak)', async () => {190 let actualEntity;191 let expectedEntity;192 try {193 expectedEntity = new Error('Error at DB');194 knexTracker.on('query', (query, step) => {195 expect(query.method).toBe('select');196 query.reject(expectedEntity);197 });198 actualEntity = await entityRepository.getFollowers(1);199 }200 catch (error) {201 expect(error.message).toEqual('Error at DB');202 }203 });204 });205 describe('getFollowerIds method', () => {206 it('get an array of user IDs', async () => {207 const expectedEntity = [1, 2];208 knexTracker.on('query', (query, step) => {209 expect(query.method).toBe('select');210 query.response(expectedEntity);211 });212 const actualEntity = await entityRepository.getFollowerIds(1);213 expect(actualEntity).toEqual(expectedEntity);214 });215 it('handles errors when they arise (no leak)', async () => {216 let actualEntity;217 let expectedEntity;218 try {219 expectedEntity = new Error('Error at DB');220 knexTracker.on('query', (query, step) => {221 expect(query.method).toBe('select');222 query.reject(expectedEntity);223 });224 actualEntity = await entityRepository.getFollowerIds(1);225 return actualEntity226 }227 catch (error) {228 expect(error.message).toEqual('Error at DB');229 }230 });231 });232 describe('getFollowees method', () => {233 it('get an array of user IDs', async () => {234 const expectedEntity = [1, 2];235 knexTracker.on('query', (query, step) => {236 expect(query.method).toBe('select');237 query.response(expectedEntity);238 });239 const actualEntity = await entityRepository.getFollowees(1);240 expect(actualEntity).toEqual(expectedEntity);241 });242 it('handles errors when they arise (no leak)', async () => {243 let actualEntity;244 let expectedEntity;245 try {246 expectedEntity = new Error('Error at DB');247 knexTracker.on('query', (query, step) => {248 expect(query.method).toBe('select');249 query.reject(expectedEntity);250 });251 actualEntity = await entityRepository.getFollowees(1);252 return actualEntity253 }254 catch (error) {255 expect(error.message).toEqual('Error at DB');256 }257 });258 });259 describe('getCollectionByIdentifierSpecial method', () => {260 it('get an array of relational objects based on identifier WITHOUT SPECIAL', async () => {261 const expectedEntity = [{object: 1}, {object: 2}];262 knexTracker.on('query', (query, step) => {263 expect(query.method).toBe('select');264 query.response(expectedEntity);265 });266 const actualEntity = await entityRepository.getCollectionByIdentifierSpecial(1, 'component_id');267 expect(actualEntity).toEqual(expectedEntity);268 });269 it('get an array of relational objects based on identifier WITH SPECIAL', async () => {270 const expectedEntity = [{object: 1}, {object: 2}];271 knexTracker.on('query', (query, step) => {272 expect(query.method).toBe('select');273 query.response(expectedEntity);274 });275 const actualEntity = await entityRepository.getCollectionByIdentifierSpecial(1, 'vote_id', 'vote');276 expect(actualEntity).toEqual(expectedEntity);277 });278 it('handles errors when they arise (no leak)', async () => {279 let actualEntity;280 let expectedEntity;281 try {282 expectedEntity = new Error('Error at DB');283 knexTracker.on('query', (query, step) => {284 expect(query.method).toBe('select');285 query.reject(expectedEntity);286 });287 actualEntity = await entityRepository.getCollectionByIdentifierSpecial(1, 'component_id');288 return actualEntity289 }290 catch (error) {291 expect(error.message).toEqual('Error at DB');292 }293 });294 });295 describe('getFansByComponent method', () => {296 it('get an array of fan objects based on component id', async () => {297 const expectedEntity = [{object: 1}, {object: 2}];298 knexTracker.on('query', (query, step) => {299 expect(query.method).toBe('select');300 query.response(expectedEntity);301 });302 const actualEntity = await entityRepository.getFansByComponent(1);303 expect(actualEntity).toEqual(expectedEntity);304 });305 it('handles errors when they arise (no leak)', async () => {306 let actualEntity;307 let expectedEntity;308 try {309 expectedEntity = new Error('Error at DB');310 knexTracker.on('query', (query, step) => {311 expect(query.method).toBe('select');312 query.reject(expectedEntity);313 });314 actualEntity = await entityRepository.getFansByComponent(1);315 return actualEntity316 }317 catch (error) {318 expect(error.message).toEqual('Error at DB');319 }320 });321 });322 describe('checkForDuplicateRelation method', () => {323 it('get an array of user-component objects based on those two ids', async () => {324 const expectedEntity = [{object: 1}, {object: 2}];325 knexTracker.on('query', (query, step) => {326 expect(query.method).toBe('select');327 query.response(expectedEntity);328 });329 const actualEntity = await entityRepository.checkForDuplicateRelation(1, 1);330 expect(actualEntity).toEqual(expectedEntity);331 });332 it('handles errors when they arise (no leak)', async () => {333 let actualEntity;334 let expectedEntity;335 try {336 expectedEntity = new Error('Error at DB');337 knexTracker.on('query', (query, step) => {338 expect(query.method).toBe('select');339 query.reject(expectedEntity);340 });341 actualEntity = await entityRepository.checkForDuplicateRelation(1, 1);342 return actualEntity343 }344 catch (error) {345 expect(error.message).toEqual('Error at DB');346 }347 });348 });349 describe('checkForDuplicateTag method', () => {350 it('get an array of tag-component objects based on those two ids', async () => {351 const expectedEntity = [{object: 1}, {object: 2}];352 knexTracker.on('query', (query, step) => {353 expect(query.method).toBe('select');354 query.response(expectedEntity);355 });356 const actualEntity = await entityRepository.checkForDuplicateTag(1, 1);357 expect(actualEntity).toEqual(expectedEntity);358 });359 it('handles errors when they arise (no leak)', async () => {360 let actualEntity;361 let expectedEntity;362 try {363 expectedEntity = new Error('Error at DB');364 knexTracker.on('query', (query, step) => {365 expect(query.method).toBe('select');366 query.reject(expectedEntity);367 });368 actualEntity = await entityRepository.checkForDuplicateTag(1, 1);369 return actualEntity370 }371 catch (error) {372 expect(error.message).toEqual('Error at DB');373 }374 });375 });376 describe('checkForDuplicateTag method', () => {377 it('get an array of follower-followee objects based on those two ids', async () => {378 const expectedEntity = [{object: 1}, {object: 2}];379 knexTracker.on('query', (query, step) => {380 expect(query.method).toBe('select');381 query.response(expectedEntity);382 });383 const actualEntity = await entityRepository.checkForDuplicateFollow(1, 1);384 expect(actualEntity).toEqual(expectedEntity);385 });386 it('handles errors when they arise (no leak)', async () => {387 let actualEntity;388 let expectedEntity;389 try {390 expectedEntity = new Error('Error at DB');391 knexTracker.on('query', (query, step) => {392 expect(query.method).toBe('select');393 query.reject(expectedEntity);394 });395 actualEntity = await entityRepository.checkForDuplicateFollow(1, 1);396 return actualEntity397 }398 catch (error) {399 expect(error.message).toEqual('Error at DB');400 }401 });402 });403 describe('createNew method', () => {404 it('get a single object', async () => {405 const expectedEntity = [{object: 1}];406 knexTracker.on('query', (query, step) => {407 expect(query.method).toBe('insert');408 query.response(expectedEntity);409 });410 const actualEntity = await entityRepository.createNew({'user_data': 1});411 expect(actualEntity).toEqual(expectedEntity[0]);412 });413 it('handles errors when they arise (no leak)', async () => {414 let actualEntity;415 let expectedEntity;416 try {417 expectedEntity = new Error('Error at DB');418 knexTracker.on('query', (query, step) => {419 expect(query.method).toBe('insert');420 query.reject(expectedEntity);421 });422 actualEntity = await entityRepository.createNew({'user_data': 1});423 }424 catch (error) {425 expect(error.message).toEqual('Error at DB');426 }427 });428 });429 describe('update entity method', () => {430 it('get a single object back based on id', async () => {431 const expectedEntity = [{object: 1}];432 knexTracker.on('query', (query, step) => {433 expect(query.method).toBe('update');434 query.response(expectedEntity);435 });436 const actualEntity = await entityRepository.update({id: 1});437 expect(actualEntity).toEqual(expectedEntity[0]);438 });439 it('handles errors when they arise (no leak)', async () => {440 let actualEntity;441 let expectedEntity;442 try {443 expectedEntity = new Error('Error at DB');444 knexTracker.on('query', (query, step) => {445 expect(query.method).toBe('update');446 query.reject(expectedEntity);447 });448 actualEntity = await entityRepository.update({id: 1});449 }450 catch (error) {451 expect(error.message).toEqual('Error at DB');452 }453 });454 });455 describe('delete (actually soft del for DEAD BEE) entity method', () => {456 it('get a single object back based on id of "deleted" user', async () => {457 const expectedEntity = [{object: 1}];458 knexTracker.on('query', (query, step) => {459 expect(query.method).toBe('update');460 query.response(expectedEntity);461 });462 const actualEntity = await entityRepository.delete({id: 1});463 expect(actualEntity).toEqual(expectedEntity[0]);464 });465 it('handles errors when they arise (no leak) ', async () => {466 let actualEntity;467 let expectedEntity;468 try {469 expectedEntity = new Error('Error at DB');470 knexTracker.on('query', (query, step) => {471 expect(query.method).toBe('update');472 query.reject(expectedEntity);473 });474 actualEntity = await entityRepository.delete({id: 1});475 }476 catch (error) {477 expect(error.message).toEqual('Error at DB');478 }479 });480 });481 describe('deleteComponent (actually soft del for components) entity method', () => {482 it('get a single object back based on id of "deleted" component', async () => {483 const expectedEntity = [{object: 1}];484 knexTracker.on('query', (query, step) => {485 expect(query.method).toBe('update');486 query.response(expectedEntity);487 });488 const actualEntity = await entityRepository.deleteComponent(1);489 expect(actualEntity).toEqual(expectedEntity[0]);490 });491 it('handles errors when they arise (no leak) ', async () => {492 let actualEntity;493 let expectedEntity;494 try {495 expectedEntity = new Error('Error at DB');496 knexTracker.on('query', (query, step) => {497 expect(query.method).toBe('update');498 query.reject(expectedEntity);499 });500 actualEntity = await entityRepository.deleteComponent(1);501 }502 catch (error) {503 expect(error.message).toEqual('Error at DB');504 }505 });506 });507 describe('hardDelete entity method', () => {508 it('get a single object back based on id of deleted entity', async () => {509 const expectedEntity = [{object: 1}];510 knexTracker.on('query', (query, step) => {511 expect(query.method).toBe('del');512 query.response(expectedEntity);513 });514 const actualEntity = await entityRepository.hardDelete(1);515 expect(actualEntity).toEqual(expectedEntity[0]);516 });517 it('handles errors when they arise (no leak) ', async () => {518 let actualEntity;519 let expectedEntity;520 try {521 expectedEntity = new Error('Error at DB');522 knexTracker.on('query', (query, step) => {523 expect(query.method).toBe('del');524 query.reject(expectedEntity);525 });526 actualEntity = await entityRepository.hardDelete(1);527 }528 catch (error) {529 expect(error.message).toEqual('Error at DB');530 }531 });532 });533 describe('hardDeleteByUser entity method', () => {534 it('get a single object back based on id of deleted user-component relation', async () => {535 const expectedEntity = [{object: 1}];536 knexTracker.on('query', (query, step) => {537 expect(query.method).toBe('del');538 query.response(expectedEntity);539 });540 const actualEntity = await entityRepository.hardDeleteByUser(1, 1);541 expect(actualEntity).toEqual(expectedEntity[0]);542 });543 it('handles errors when they arise (no leak) ', async () => {544 let actualEntity;545 let expectedEntity;546 try {547 expectedEntity = new Error('Error at DB');548 knexTracker.on('query', (query, step) => {549 expect(query.method).toBe('del');550 query.reject(expectedEntity);551 });552 actualEntity = await entityRepository.hardDeleteByUser(1, 1);553 }554 catch (error) {555 expect(error.message).toEqual('Error at DB');556 }557 });558 });559 describe('hardDeleteByTag entity method', () => {560 it('get a single object back based on id of deleted tag-component relation', async () => {561 const expectedEntity = [{object: 1}];562 knexTracker.on('query', (query, step) => {563 expect(query.method).toBe('del');564 query.response(expectedEntity);565 });566 const actualEntity = await entityRepository.hardDeleteByTag(1, 1);567 expect(actualEntity).toEqual(expectedEntity[0]);568 });569 it('handles errors when they arise (no leak) ', async () => {570 let actualEntity;571 let expectedEntity;572 try {573 expectedEntity = new Error('Error at DB');574 knexTracker.on('query', (query, step) => {575 expect(query.method).toBe('del');576 query.reject(expectedEntity);577 });578 actualEntity = await entityRepository.hardDeleteByTag(1, 1);579 }580 catch (error) {581 expect(error.message).toEqual('Error at DB');582 }583 });584 });585 describe('hardDeleteFollow entity method', () => {586 it('get a single object back based on id of deleted follower-followee relation', async () => {587 const expectedEntity = [{object: 1}];588 knexTracker.on('query', (query, step) => {589 expect(query.method).toBe('del');590 query.response(expectedEntity);591 });592 const actualEntity = await entityRepository.hardDeleteFollow(1, 1);593 expect(actualEntity).toEqual(expectedEntity[0]);594 });595 it('handles errors when they arise (no leak) ', async () => {596 let actualEntity;597 let expectedEntity;598 try {599 expectedEntity = new Error('Error at DB');600 knexTracker.on('query', (query, step) => {601 expect(query.method).toBe('del');602 query.reject(expectedEntity);603 });604 actualEntity = await entityRepository.hardDeleteFollow(1, 1);605 }606 catch (error) {607 expect(error.message).toEqual('Error at DB');608 }609 });610 });611 afterEach(() => {612 knexTracker.uninstall();613 });614 afterAll(() => {615 KnexMock.unmock(db);616 });...

Full Screen

Full Screen

EntityResolver.test.js

Source:EntityResolver.test.js Github

copy

Full Screen

1const EntityResolver = require('./EntityResolver')2describe('EntityResolver Tests', () => {3 const entityService = {4 getAll: jest.fn(),5 getById: jest.fn(),6 getByIdentifier: jest.fn(),7 getOwnerByParentComponentId: jest.fn(),8 getByUserId: jest.fn(),9 getParent: jest.fn(),10 getChildren: jest.fn(),11 getCloneSource: jest.fn(),12 getClones: jest.fn(),13 getTagsByComponent: jest.fn(),14 getFollowers: jest.fn(),15 getFollowees: jest.fn(),16 getActivity: jest.fn(),17 getComment: jest.fn(),18 getByIdentifierSpecial: jest.fn(),19 getByUserIdSpecial: jest.fn(),20 createNew: jest.fn(),21 update: jest.fn(),22 delete: jest.fn(),23 };24 const entityResolver = new EntityResolver({25 entityName: 'Entity',26 entityService27 });28 describe('getAll method', () => {29 const parent = {id: 1};30 const args = {id: 1};31 const context = {authenticatedUserId: 1};32 it('should return all entries from entity', async () => {33 const expectedEntity = [{id: 1}];34 entityService.getAll.mockReturnValueOnce(Promise.resolve(expectedEntity));35 const actualEntity = await entityResolver.getAll(parent, args, context);36 expect(actualEntity).toEqual(expectedEntity);37 });38 it('should deal with errors when they occur', async () => {39 try {40 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');41 entityService.getAll.mockReturnValueOnce(Promise.reject(expectedEntity));42 const actualEntity = await entityResolver.getAll(parent, args, context);43 return actualEntity44 }45 catch (error) {46 expect(error.message).toEqual('Error occurred. Please try again.');47 }48 });49 });50 describe('getById method', () => {51 const expectedEntity = {id: 1};52 const parent = {id: 1};53 const args = {id: 1};54 const context = {authenticatedUserId: 1};55 it('should return single entry from entity', async () => {56 const parent = {};57 entityService.getById.mockReturnValueOnce(Promise.resolve(expectedEntity));58 const actualEntity = await entityResolver.getById(parent, args, context);59 expect(actualEntity).toEqual(expectedEntity);60 });61 it('should deal with errors when they occur', async () => {62 try {63 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');64 entityService.getById.mockReturnValueOnce(Promise.reject(expectedEntity));65 const actualEntity = await entityResolver.getById(parent, args, context);66 return actualEntity67 }68 catch (error) {69 expect(error.message).toEqual('Error occurred. Please try again.');70 }71 });72 });73 describe('getOwnerByParentComponentId method', () => {74 const args = {id: 1};75 const parent = {id: 1};76 const context = {authenticatedUserId: 1};77 it('should return single entry from entity', async () => {78 const expectedEntity = {id: 1};79 entityService.getById.mockReturnValueOnce(Promise.resolve(expectedEntity));80 const actualEntity = await entityResolver.getOwnerByParentComponentId(parent, args, context);81 expect(actualEntity).toEqual(expectedEntity);82 });83 it('should deal with errors when they occur', async () => {84 try {85 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');86 entityService.getById.mockReturnValueOnce(Promise.reject(expectedEntity));87 const actualEntity = await entityResolver.getOwnerByParentComponentId(parent, args, context);88 return actualEntity89 }90 catch (error) {91 expect(error.message).toEqual('Error occurred. Please try again.');92 }93 });94 });95 describe('getByIdentifier method', () => {96 const parent = {id: 1};97 const args = {id: 1};98 const context = {authenticatedUserId: 1};99 it('should return single entry from entity', async () => {100 const expectedEntity = {id: 1};101 entityService.getByIdentifier.mockReturnValueOnce(Promise.resolve(expectedEntity));102 const actualEntity = await entityResolver.getByIdentifier(parent, args, context);103 expect(actualEntity).toEqual(expectedEntity);104 });105 it('should deal with errors when they occur', async () => {106 try {107 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');108 entityService.getByIdentifier.mockReturnValueOnce(Promise.reject(expectedEntity));109 const actualEntity = await entityResolver.getByIdentifier(parent, args, context);110 return actualEntity111 }112 catch (error) {113 expect(error.message).toEqual('Error occurred. Please try again.');114 }115 });116 });117 describe('getByUserId method', () => {118 const parent = {id: 1};119 const args = {id: 1};120 const context = {authenticatedUserId: 1};121 it('should return single entry from entity', async () => {122 const expectedEntity = {id: 1};123 entityService.getByUserId.mockReturnValueOnce(Promise.resolve(expectedEntity));124 const actualEntity = await entityResolver.getByUserId(parent, args, context);125 expect(actualEntity).toEqual(expectedEntity);126 });127 it('should deal with errors when they occur', async () => {128 try {129 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');130 entityService.getByUserId.mockReturnValueOnce(Promise.reject(expectedEntity));131 const actualEntity = await entityResolver.getByUserId(parent, args, context);132 return actualEntity133 }134 catch (error) {135 expect(error.message).toEqual('Error occurred. Please try again.');136 }137 });138 });139 describe('getParent method', () => {140 const parent = {id: 1};141 const args = {id: 1};142 const context = {authenticatedUserId: 1};143 it('should return single entry from entity', async () => {144 const expectedEntity = {id: 1};145 entityService.getById.mockReturnValueOnce(Promise.resolve(expectedEntity));146 const actualEntity = await entityResolver.getParent(parent, args, context);147 expect(actualEntity).toEqual(expectedEntity);148 });149 it('should deal with errors when they occur', async () => {150 try {151 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');152 entityService.getById.mockReturnValueOnce(Promise.reject(expectedEntity));153 const actualEntity = await entityResolver.getParent(parent, args, context);154 return actualEntity155 }156 catch (error) {157 expect(error.message).toEqual('Error occurred. Please try again.');158 }159 });160 });161 describe('getChildren method', () => {162 const parent = {id: 1};163 const args = {id: 1};164 const context = {authenticatedUserId: 1};165 it('should return array of entries from entity', async () => {166 const expectedEntity = [{id: 1}, {id: 1}];167 entityService.getChildren.mockReturnValueOnce(Promise.resolve(expectedEntity));168 const actualEntity = await entityResolver.getChildren(parent, args, context);169 expect(actualEntity).toEqual(expectedEntity);170 });171 it('should deal with errors when they occur', async () => {172 try {173 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');174 entityService.getChildren.mockReturnValueOnce(Promise.reject(expectedEntity));175 const actualEntity = await entityResolver.getChildren(parent, args, context);176 return actualEntity177 }178 catch (error) {179 expect(error.message).toEqual('Error occurred. Please try again.');180 }181 });182 });183 describe('getCloneSource method', () => {184 const parent = {id: 1};185 const args = {id: 1};186 const context = {authenticatedUserId: 1};187 it('should return array of entries from entity', async () => {188 const expectedEntity = [{id: 1}, {id: 1}];189 entityService.getById.mockReturnValueOnce(Promise.resolve(expectedEntity));190 const actualEntity = await entityResolver.getCloneSource(parent, args, context);191 expect(actualEntity).toEqual(expectedEntity);192 });193 it('should deal with errors when they occur', async () => {194 try {195 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');196 entityService.getById.mockReturnValueOnce(Promise.reject(expectedEntity));197 const actualEntity = await entityResolver.getCloneSource(parent, args, context);198 return actualEntity199 }200 catch (error) {201 expect(error.message).toEqual('Error occurred. Please try again.');202 }203 });204 });205 describe('getClones method', () => {206 const parent = {id: 1};207 const args = {id: 1};208 const context = {authenticatedUserId: 1};209 it('should return array of entries from entity', async () => {210 const expectedEntity = [{id: 1}, {id: 1}];211 entityService.getClones.mockReturnValueOnce(Promise.resolve(expectedEntity));212 const actualEntity = await entityResolver.getClones(parent, args, context);213 expect(actualEntity).toEqual(expectedEntity);214 });215 it('should deal with errors when they occur', async () => {216 try {217 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');218 entityService.getClones.mockReturnValueOnce(Promise.reject(expectedEntity));219 const actualEntity = await entityResolver.getClones(parent, args, context);220 return actualEntity221 }222 catch (error) {223 expect(error.message).toEqual('Error occurred. Please try again.');224 }225 });226 });227 describe('getTagsByComponent method', () => {228 const parent = {id: 1};229 const args = {id: 1};230 const context = {authenticatedUserId: 1};231 it('should return array of entries from entity', async () => {232 const expectedEntity = [{id: 1}, {id: 1}];233 entityService.getTagsByComponent.mockReturnValueOnce(Promise.resolve(expectedEntity));234 const actualEntity = await entityResolver.getTagsByComponent(parent, args, context);235 expect(actualEntity).toEqual(expectedEntity);236 });237 it('should deal with errors when they occur', async () => {238 try {239 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');240 entityService.getTagsByComponent.mockReturnValueOnce(Promise.reject(expectedEntity));241 const actualEntity = await entityResolver.getTagsByComponent(parent, args, context);242 return actualEntity243 }244 catch (error) {245 expect(error.message).toEqual('Error occurred. Please try again.');246 }247 });248 });249 describe('getFollowers method', () => {250 const parent = {id: 1};251 const args = {id: 1};252 const context = {authenticatedUserId: 1};253 it('should return array of entries from entity', async () => {254 const expectedEntity = [{id: 1}, {id: 1}];255 entityService.getFollowers.mockReturnValueOnce(Promise.resolve(expectedEntity));256 const actualEntity = await entityResolver.getFollowers(parent, args, context);257 expect(actualEntity).toEqual(expectedEntity);258 });259 it('should deal with errors when they occur', async () => {260 try {261 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');262 entityService.getFollowers.mockReturnValueOnce(Promise.reject(expectedEntity));263 const actualEntity = await entityResolver.getFollowers(parent, args, context);264 return actualEntity265 }266 catch (error) {267 expect(error.message).toEqual('Error occurred. Please try again.');268 }269 });270 });271 describe('getFollowers method', () => {272 const parent = {id: 1};273 const args = {id: 1};274 const context = {authenticatedUserId: 1};275 it('should return array of entries from entity', async () => {276 const expectedEntity = [{id: 1}, {id: 1}];277 entityService.getFollowees.mockReturnValueOnce(Promise.resolve(expectedEntity));278 const actualEntity = await entityResolver.getFollowees(parent, args, context);279 expect(actualEntity).toEqual(expectedEntity);280 });281 it('should deal with errors when they occur', async () => {282 try {283 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');284 entityService.getFollowees.mockReturnValueOnce(Promise.reject(expectedEntity));285 const actualEntity = await entityResolver.getFollowees(parent, args, context);286 return actualEntity287 }288 catch (error) {289 expect(error.message).toEqual('Error occurred. Please try again.');290 }291 });292 });293 describe('getByIdentifierSpecial method', () => {294 const parent = {id: 1};295 const args = {id: 1};296 const context = {authenticatedUserId: 1};297 it('should return array of entries from entity', async () => {298 const expectedEntity = [{id: 1}, {id: 1}];299 entityService.getByIdentifierSpecial.mockReturnValueOnce(Promise.resolve(expectedEntity));300 const actualEntity = await entityResolver.getByIdentifierSpecial(parent, args, context);301 expect(actualEntity).toEqual(expectedEntity);302 });303 it('should deal with errors when they occur', async () => {304 try {305 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');306 entityService.getByIdentifierSpecial.mockReturnValueOnce(Promise.reject(expectedEntity));307 const actualEntity = await entityResolver.getByIdentifierSpecial(parent, args, context);308 return actualEntity309 }310 catch (error) {311 expect(error.message).toEqual('Error occurred. Please try again.');312 }313 });314 });315 describe('getByUserIdSpecial method', () => {316 const parent = {id: 1};317 const args = {id: 1};318 const context = {authenticatedUserId: 1};319 it('should return specific entry from entity', async () => {320 const expectedEntity = {id: 2};321 entityService.getByUserIdSpecial.mockReturnValueOnce(Promise.resolve(expectedEntity));322 const actualEntity = await entityResolver.getByUserIdSpecial(parent, args, context);323 expect(actualEntity).toEqual(expectedEntity);324 });325 it('should deal with errors when they occur', async () => {326 try {327 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');328 entityService.getByUserIdSpecial.mockReturnValueOnce(Promise.reject(expectedEntity));329 const actualEntity = await entityResolver.getByUserIdSpecial(parent, args, context);330 return actualEntity331 }332 catch (error) {333 expect(error.message).toEqual('Error occurred. Please try again.');334 }335 });336 });337 describe('getActivity method', () => {338 const parent = {id: 1};339 const args = {id: 1};340 const context = {authenticatedUserId: 1};341 it('should return array of activities from activity entity', async () => {342 const expectedEntity = [{id: 1}, {id: 1}];343 entityService.getActivity.mockReturnValueOnce(Promise.resolve(expectedEntity));344 const actualEntity = await entityResolver.getActivity(parent, args, context);345 expect(actualEntity).toEqual(expectedEntity);346 });347 it('should deal with errors when they occur', async () => {348 try {349 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');350 entityService.getActivity.mockReturnValueOnce(Promise.reject(expectedEntity));351 const actualEntity = await entityResolver.getActivity(parent, args, context);352 return actualEntity353 }354 catch (error) {355 expect(error.message).toEqual('Error occurred. Please try again.');356 }357 });358 });359 describe('getComment method', () => {360 const parent = {id: 1};361 const args = {id: 1};362 const context = {authenticatedUserId: 1};363 it('should return specific comment', async () => {364 const expectedEntity = {id: 2};365 entityService.getComment.mockReturnValueOnce(Promise.resolve(expectedEntity));366 const actualEntity = await entityResolver.getComment(parent, args, context);367 expect(actualEntity).toEqual(expectedEntity);368 });369 it('should deal with errors when they occur', async () => {370 try {371 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');372 entityService.getComment.mockReturnValueOnce(Promise.reject(expectedEntity));373 const actualEntity = await entityResolver.getComment(parent, args, context);374 return actualEntity375 }376 catch (error) {377 expect(error.message).toEqual('Error occurred. Please try again.');378 }379 });380 });381 describe('createNew method', () => {382 const parent = {id: 1};383 const args = {id: 1};384 const context = {authenticatedUserId: 1};385 it('should return specific created entity', async () => {386 const expectedEntity = {id: 2};387 entityService.createNew.mockReturnValueOnce(Promise.resolve(expectedEntity));388 const actualEntity = await entityResolver.createNew(parent, args, context);389 expect(actualEntity).toEqual(expectedEntity);390 });391 it('should deal with errors when they occur', async () => {392 try {393 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');394 entityService.createNew.mockReturnValueOnce(Promise.reject(expectedEntity));395 const actualEntity = await entityResolver.createNew(parent, args, context);396 return actualEntity397 }398 catch (error) {399 expect(error.message).toEqual('Error occurred. Please try again.');400 }401 });402 it('should deal with MISSING errors when they occur', async () => {403 try {404 const expectedEntity = new Error('MISSING DATA');405 entityService.createNew.mockReturnValueOnce(Promise.reject(expectedEntity));406 const actualEntity = await entityResolver.createNew(parent, args, context);407 return actualEntity408 }409 catch (error) {410 expect(error.message).toEqual('Incomplete Information: MISSING DATA');411 }412 });413 it('should deal with DUPLICATE errors when they occur', async () => {414 try {415 const expectedEntity = new Error('DUPLICATE: EMAIL ADDRESS');416 entityService.createNew.mockReturnValueOnce(Promise.reject(expectedEntity));417 const actualEntity = await entityResolver.createNew(parent, args, context);418 return actualEntity419 }420 catch (error) {421 expect(error.message).toEqual('DUPLICATE: EMAIL ADDRESS');422 }423 });424 });425 describe('update method', () => {426 const parent = {id: 1};427 const args = {id: 1};428 const context = {authenticatedUserId: 1};429 it('should return specific updated entity', async () => {430 const expectedEntity = {id: 2};431 entityService.update.mockReturnValueOnce(Promise.resolve(expectedEntity));432 const actualEntity = await entityResolver.update(parent, args, context);433 expect(actualEntity).toEqual(expectedEntity);434 });435 it('should deal with errors when they occur', async () => {436 try {437 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');438 entityService.update.mockReturnValueOnce(Promise.reject(expectedEntity));439 const actualEntity = await entityResolver.update(parent, args, context);440 return actualEntity441 }442 catch (error) {443 expect(error.message).toEqual('Error occurred. Please try again.');444 }445 });446 });447 describe('delete method', () => {448 const parent = {id: 1};449 const args = {id: 1};450 const context = {authenticatedUserId: 1};451 it('should return specific deleted entity', async () => {452 const expectedEntity = {id: 2};453 entityService.delete.mockReturnValueOnce(Promise.resolve(expectedEntity));454 const actualEntity = await entityResolver.delete(parent, args, context);455 expect(actualEntity).toEqual(expectedEntity);456 });457 it('should deal with errors when they occur', async () => {458 try {459 const expectedEntity = new Error('Arbitrary error bubbling up from SERVICE');460 entityService.delete.mockReturnValueOnce(Promise.reject(expectedEntity));461 const actualEntity = await entityResolver.delete(parent, args, context);462 return actualEntity463 }464 catch (error) {465 expect(error.message).toEqual('Error occurred. Please try again.');466 }467 });468 });...

Full Screen

Full Screen

CoinTableContainer_spec.js

Source:CoinTableContainer_spec.js Github

copy

Full Screen

1import React from 'react';2import { shallow, render } from 'enzyme';3import { expect } from 'chai';4import sinon from 'sinon';5import CoinTableContainer from '../../containers/CoinTableContainer';6import CoinTable from '../../CoinTable';7import mockStore from '../../mockStore';8import Api from '../../Api';9const getWrapper = (props, initState = {10 resource: {11 entities: [],12 isLoading: false,13 },14}) => shallow(15 <CoinTableContainer />,16 {17 context: {18 store: mockStore(initState),19 },20 }21);22describe('<CoinTableContainer>', () => {23 it('renders okay', () => {24 expect(() => {25 getWrapper();26 }).not.to.throw();27 });28 it('passes the entities values', () => {29 const expectedEntity = {30 id: 12,31 name: 'My Coin',32 price: 39478230,33 };34 const expectedLoading = true;35 const wrapper = getWrapper(null, {36 resource: {37 entities: {38 [expectedEntity.id]: expectedEntity,39 },40 ids: [expectedEntity.id],41 isLoading: expectedLoading,42 },43 });44 const { coins, isLoading, fetch } = wrapper.props();45 expect(coins.length).to.eq(1);46 expect(typeof fetch).to.eq('function');47 const fetchStub = sinon.stub(Api, 'get').returns(Promise.resolve({ data: [] }));48 expect(fetchStub.callCount).to.eq(0);49 fetch();50 expect(fetchStub.callCount).to.eq(1);51 expect(fetchStub.calledWith('transactions?_limit=10')).to.eq(true);52 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const expectedEntity = require('stryker-parent').expectedEntity;2const expectedEntity = require('stryker-parent').expectedEntity;3const expectedEntity = require('stryker-parent').expectedEntity;4const expectedEntity = require('stryker-parent').expectedEntity;5const expectedEntity = require('stryker-parent').expectedEntity;6const expectedEntity = require('stryker-parent').expectedEntity;7const expectedEntity = require('stryker-parent').expectedEntity;8const expectedEntity = require('stryker-parent').expectedEntity;9const expectedEntity = require('stryker-parent').expectedEntity;10const expectedEntity = require('stryker-parent').expectedEntity;11const expectedEntity = require('stryker-parent').expectedEntity;12const expectedEntity = require('stryker-parent').expectedEntity;13const expectedEntity = require('stryker-parent').expectedEntity;14const expectedEntity = require('stryker-parent').expectedEntity;15const expectedEntity = require('stryker-parent').expectedEntity;16const expectedEntity = require('stryker-parent').expectedEntity;17const expectedEntity = require('stryker-parent').expectedEntity;18const expectedEntity = require('stryker-parent

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2stryker.expectedEntity('test.js');3var stryker = require('stryker-parent');4stryker.expectedEntity('test.js');5var stryker = require('stryker-parent');6stryker.expectedEntity('test.js');7var stryker = require('stryker-parent');8stryker.expectedEntity('test.js');9var stryker = require('stryker-parent');10stryker.expectedEntity('test.js');11var stryker = require('stryker-parent');12stryker.expectedEntity('test.js');13var stryker = require('stryker-parent');14stryker.expectedEntity('test.js');15var stryker = require('stryker-parent');16stryker.expectedEntity('test.js');17var stryker = require('stryker-parent');18stryker.expectedEntity('test.js');19var stryker = require('stryker-parent');20stryker.expectedEntity('test.js');21var stryker = require('stryker-parent');22stryker.expectedEntity('test.js');23var stryker = require('stryker-parent');24stryker.expectedEntity('test.js');25var stryker = require('stryker-parent');26stryker.expectedEntity('test.js');27var stryker = require('stryker-parent');28stryker.expectedEntity('test.js');29var stryker = require('stryker-parent');30stryker.expectedEntity('test.js');31var stryker = require('stryker-parent');32stryker.expectedEntity('test.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1const expectedEntity = require('stryker-parent').expectedEntity;2console.log(expectedEntity);3const fs = require('fs');4const path = require('path');5const expectedEntity = fs.readFileSync(path.join(__dirname, 'expected-entity.txt'), 'utf8');6module.exports = {7};

Full Screen

Using AI Code Generation

copy

Full Screen

1const {expectedEntity} = require('stryker-parent');2const {expect} = require('chai');3describe('expectedEntity', () => {4 it('should return a string', () => {5 expect(expectedEntity()).to.be.a('string');6 });7});8const {expectedEntity} = require('stryker-child');9const {expect} = require('chai');10describe('expectedEntity', () => {11 it('should return a string', () => {12 expect(expectedEntity()).to.be.a('string');13 });14});15module.exports = function(config) {16 config.set({17 });18};19function expectedEntity() {20 return 'parent';21}22module.exports = {23};24const {expectedEntity} = require('stryker-parent');25function expectedEntity() {26 return 'child';27}28module.exports = {29};3018:11:59 (3692) INFO SandboxPool Creating 1 test runners (based on CPU count)3118:11:59 (3692) INFO Stryker 1 Mutant(s) generated3218:11:59 (3692) INFO Stryker 1 Mutant(s) tested (0 survived, 1 timed out)

Full Screen

Using AI Code Generation

copy

Full Screen

1var expectedEntity = require('stryker-parent').expectedEntity;2var test = require('tape');3var browserify = require('browserify');4var vm = require('vm');5var fs = require('fs');6var path = require('path');7var expected = expectedEntity('test.js');8test('should not throw an error', function (t) {9 t.plan(1);10 var b = browserify();11 b.add(path.join(__dirname, 'test.js'));12 b.bundle(function (err, src) {13 if (err) {14 t.fail(err);15 }16 var c = {17 };18 vm.runInNewContext(src, c);19 });20});21var expectedEntity = require('stryker-parent').expectedEntity;22var test = require('tape');23var browserify = require('browserify');24var vm = require('vm');25var fs = require('fs');26var path = require('path');27var expected = expectedEntity('test.js');28test('should not throw an error', function (t) {29 t.plan(1);30 var b = browserify();31 b.add(path.join(__dirname, 'test.js'));32 b.bundle(function (err, src) {33 if (err) {34 t.fail(err);35 }36 var c = {37 };38 vm.runInNewContext(src, c);39 });40});41var expectedEntity = require('stryker-parent').expectedEntity;42var test = require('tape');43var browserify = require('browserify');44var vm = require('vm');45var fs = require('fs');46var path = require('path');47var expected = expectedEntity('test.js');48test('should not throw an error', function (t) {49 t.plan(1);50 var b = browserify();51 b.add(path.join(__dirname, 'test.js'));52 b.bundle(function (err, src) {53 if (err) {54 t.fail(err);55 }56 var c = {57 };58 vm.runInNewContext(src, c

Full Screen

Using AI Code Generation

copy

Full Screen

1const expectedEntity = require('stryker-parent').expectedEntity;2describe('test', () => {3 it('should pass', () => {4 expect(expectedEntity('test')).toBe('test');5 });6});7module.exports = function (config) {8 config.set({9 });10};11{12 "devDependencies": {13 }14}

Full Screen

Using AI Code Generation

copy

Full Screen

1const expectedEntity = require('stryker-parent').expectedEntity;2const actualEntity = require('./actualEntity');3module.exports = expectedEntity(actualEntity, 'actualEntity');4module.exports = {5};6module.exports = function(config) {7 config.set({8 });9};

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var expectedEntity = stryker.expectedEntity;3var assert = require('assert');4var entity = { name: 'foo' };5var actual = expectedEntity(entity, 'name');6assert.equal(actual, entity);7var stryker = require('stryker-parent');8var expectedEntity = stryker.expectedEntity;9var assert = require('assert');10var entity = { name: 'foo' };11var actual = expectedEntity(entity, 'name');12assert.equal(actual, entity);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { StrykerParent } = require('stryker-parent');2const expectedEntity = StrykerParent.expectedEntity;3describe('test', () => {4 it('should return expected entity', () => {5 const expected = expectedEntity('test');6 expect(expected).to.equal('test');7 });8});9 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)10 at Function.Module._load (internal/modules/cjs/loader.js:508:25)11 at Module.require (internal/modules/cjs/loader.js:638:17)12 at require (internal/modules/cjs/helpers.js:22:18)13 at Context.<anonymous> (test.js:3:23)14 at processImmediate (internal/timers.js:439:21)

Full Screen

Using AI Code Generation

copy

Full Screen

1const expectedEntity = require('stryker-parent').expectedEntity;2describe('test', () => {3 it('should return the expected entity', () => {4 const entity = expectedEntity();5 });6});

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 stryker-parent 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