Advertisement
ilianrusev

Untitled

Feb 14th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  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.equal(0)
  14. })
  15.  
  16. })
  17.  
  18. describe('testing .add()', () => {
  19. it(`valid obj passed as input: output -> its id in the collection`,
  20. () => {
  21. expect(instance.add({ name: '', age: 1, birthday: {} })).to
  22. .equal(0)
  23. }
  24. )
  25. })
  26.  
  27. describe(`testing .getId()`, () => {
  28. it(`input ID which is not present in the data collection -> throw`,
  29. () => {
  30. expect(() => instance.getId(1)).to
  31. .throw('Entity with id: 1 does not exist!')
  32. }
  33. )
  34. })
  35.  
  36. describe(`testing .update()`, () => {
  37. it(`input ID which is not present in the data collection -> throw`,
  38. () => {
  39. expect(() => instance.update(0, {},)).to
  40. .throw(`Entity with id: 0 does not exist!`)
  41. }
  42. )
  43. it(`any property is missing from input object -> throw Error`, () => {
  44. instance.add({ name: '', age: 0, birthday: {}, })
  45. expect(() => instance.update(
  46. 0,
  47. { age: 1, birthday: { date: 0 } }
  48. )).to.throw
  49. })
  50. it(`typeof input[name] !== string -> throw TypeError`, () => {
  51. instance.add({ name: '', age: 0, birthday: {}, })
  52. expect(() => instance.update(
  53. 0,
  54. { name: 0, age: 1, birthday: { date: 0 } }
  55. )).to.throw(TypeError)
  56. })
  57. })
  58.  
  59. describe(`testing .del()`, () => {
  60. it(`deletes index properly`, () => {
  61. instance.add({ name: '', age: 1, birthday: {} })
  62. instance.add({ name: '', age: 1, birthday: {} })
  63. instance.del(1)
  64. expect(instance.data.has(1)).to.equal(false)
  65. })
  66. it(`throws on index which does not exist in the collection`, () => {
  67. expect(() => instance.del(-1)).to
  68. .throw(`Entity with id: -1 does not exist!`)
  69. })
  70. })
  71. })
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement