rootInstance.spec.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { holder, rootInstanceSymbol, registerAsRootInstance, hasValidParameter, isRootInstance } from 'handsontable/utils/rootInstance';
  2. describe('rootInstance', () => {
  3. describe('.registerAsRootInstance', () => {
  4. it('should mark an object as a root instance', () => {
  5. const object = {};
  6. registerAsRootInstance(object);
  7. expect(holder.get(object)).toBe(true);
  8. });
  9. });
  10. describe('.hasValidParameter', () => {
  11. it('should return `true` when valid Symbol was passed', () => {
  12. expect(hasValidParameter(rootInstanceSymbol)).toBe(true);
  13. });
  14. it('should return `false` when Symbol with the same name was passed', () => {
  15. expect(hasValidParameter(Symbol('rootInstance'))).toBe(false);
  16. });
  17. it('should return `false` when different values provided than Symbol', () => {
  18. expect(hasValidParameter()).toBe(false);
  19. expect(hasValidParameter('')).toBe(false);
  20. expect(hasValidParameter(null)).toBe(false);
  21. expect(hasValidParameter('rootInstance')).toBe(false);
  22. expect(hasValidParameter(10)).toBe(false);
  23. });
  24. });
  25. describe('.isRootInstance', () => {
  26. it('should return `true` when an object was marked as a root instance', () => {
  27. const object = {};
  28. holder.set(object, true);
  29. expect(isRootInstance(object)).toBe(true);
  30. });
  31. it('should return \'false\' when an object was not marked as a root instance', () => {
  32. const object = {};
  33. expect(isRootInstance(object)).toBe(false);
  34. });
  35. });
  36. });