Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // 24: class - static keyword
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3.  
  4. describe('inside a class you can use the `static` keyword', () => {
  5.  
  6. describe('for methods', () => {
  7.  
  8. class IntegrationTest {}
  9. class UnitTest {}
  10.  
  11. it('a static method just has the prefix `static`', () => {
  12. class TestFactory {
  13. static makeTest() { return new UnitTest(); }
  14. }
  15.  
  16. assert.ok(TestFactory.makeTest() instanceof UnitTest);
  17. });
  18.  
  19. it('the method name can be dynamic/computed at runtime', () => {
  20. const methodName = 'createTest';
  21. class TestFactory {
  22. static [methodName]() { return new UnitTest(); }
  23. }
  24.  
  25. assert.ok(TestFactory.createTest() instanceof UnitTest);
  26. });
  27. });
  28.  
  29. describe('for accessors', () => {
  30. it('a getter name can be static, just prefix it with `static`', () => {
  31. class UnitTest {
  32. static get testType() { return 'unit'; }
  33. }
  34.  
  35. assert.equal(UnitTest.testType, 'unit');
  36. });
  37.  
  38. it('even a static getter name can be dynamic/computed at runtime', () => {
  39. const type = 'test' + 'Type';
  40. class IntegrationTest {
  41. static get [type]() { return 'integration'; }
  42. }
  43.  
  44. assert.ok('testType' in IntegrationTest);
  45. assert.equal(IntegrationTest.testType, 'integration');
  46. });
  47. });
  48.  
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement