Advertisement
Guest User

Untitled

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