Guest User

Untitled

a guest
Nov 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. // 14: destructuring - parameters
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3. // Follow the hints of the failure messages!
  4.  
  5. describe('Destructuring function parameters', () => {
  6. describe('destruct parameters', () => {
  7. it('multiple params from object', () => {
  8. const fn = ({id, name}) => {
  9. assert.equal(id, 42);
  10. assert.equal(name, 'Wolfram');
  11. };
  12. const user = {name: 'Wolfram', id: 42};
  13. fn(user);
  14. });
  15. it('multiple params from array/object', () => {
  16. const fn = ([{name}]) => {
  17. assert.equal(name, 'Alice');
  18. };
  19. const users = [{name: 'Alice'}, {name: 'Alice', id: 42}];
  20. fn(users);
  21. });
  22. });
  23. describe('default values', () => {
  24. it('for simple values', () => {
  25. const fn = (id, name='Bob') => {
  26. assert.strictEqual(id, 23);
  27. assert.strictEqual(name, 'Bob');
  28. };
  29. fn(23);
  30. });
  31. it('for a missing array value', () => {
  32. const defaultUser = {id: 23, name: 'Joe'};
  33. const fn = ([user = {id: 23, name: 'Joe'}]) => {
  34. assert.deepEqual(user, defaultUser);
  35. };
  36. fn([]);
  37. });
  38. it('mix of parameter types', () => {
  39. const fn = (id = 1, [arr = 2], {obj = 3}) => {
  40. assert.equal(id, 1);
  41. assert.equal(arr, 2);
  42. assert.equal(obj, 3);
  43. };
  44. fn(void 0, [], {});
  45. });
  46. });
  47. });
Add Comment
Please, Sign In to add comment