Liliana797979

2_repository js advanced exam

Oct 22nd, 2021
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe(`testing Repository class`, () => {
  2.     let instance = {}
  3.  
  4.     beforeEach(() => instance = new Repository({
  5.         name: 'string',
  6.         age: 'number',
  7.         birthday: 'object'
  8.     }))
  9.  
  10.  
  11.     describe('testing count prop', () => {
  12.         it(`instance.count -> 0`, () => {
  13.             expect(instance.count).to.eq(0)
  14.         })
  15.  
  16.     })
  17.  
  18.     describe('testing .add()', () => {
  19.         it(
  20.             `valid obj passed as input: output -> its id in the collection`,
  21.             () => {
  22.                 expect(instance.add({ name: '', age: 1, birthday: {} })).to
  23.                     .eq(0)
  24.             }
  25.         )
  26.     })
  27.  
  28.     describe(`testing .getId()`, () => {
  29.         it(
  30.             `input ID which is not present in the data collection -> throw`,
  31.             () => {
  32.                 expect(() => instance.getId(1)).to
  33.                     .throw('Entity with id: 1 does not exist!')
  34.             }
  35.         )
  36.     })
  37.  
  38.     describe(`testing .update()`, () => {
  39.         it(
  40.             `input ID which is not present in the data collection -> throw`,
  41.             () => {
  42.                 expect(() => instance.update(0, {},)).to
  43.                     .throw(`Entity with id: 0 does not exist!`)
  44.             }
  45.         )
  46.         it(`any property is missing from input object -> throw Error`, () => {
  47.             instance.add({ name: '', age: 0, birthday: {}, })
  48.             expect(() => instance.update(
  49.                 0,
  50.                 { age: 1, birthday: { date: 0 } }
  51.             )).to.throw
  52.         })
  53.         it(`typeof input[name] !== string -> throw TypeError`, () => {
  54.             instance.add({ name: '', age: 0, birthday: {}, })
  55.             expect(() => instance.update(
  56.                 0,
  57.                 { name: 0, age: 1, birthday: { date: 0 } }
  58.             )).to.throw(TypeError)
  59.         })
  60.     })
  61.  
  62.     describe(`testing .del()`, () => {
  63.         it(`deletes index properly`, () => {
  64.             instance.add({ name: '', age: 1, birthday: {} })
  65.             instance.add({ name: '', age: 1, birthday: {} })
  66.             instance.del(1)
  67.             expect(instance.data.has(1)).to.eq(false)
  68.         })
  69.         it(`throws on index which does not exist in the collection`, () => {
  70.             expect(() => instance.del(-1)).to
  71.                 .throw(`Entity with id: -1 does not exist!`)
  72.         })
  73.     })
  74. })
  75.  
Advertisement
Add Comment
Please, Sign In to add comment