diff --git a/src/__test__/browser.spec.ts b/src/__test__/browser.spec.ts index 1899b64..2f9c730 100644 --- a/src/__test__/browser.spec.ts +++ b/src/__test__/browser.spec.ts @@ -1,5 +1,5 @@ import _browser from '../browser'; -import { getCustomProp } from '../core/utils/customProp'; +import { getElementCustomProp } from '../core/utils/elementCustomProp'; // Reset to clean, uninitialized template const reset = () => { @@ -14,7 +14,7 @@ const reset = () => { const validateComponentFunctionality = (error = false) => { const componentElement = document.querySelector('body > div') as HTMLElement; const componentText = componentElement.querySelector('p') as HTMLElement; - const component = getCustomProp(componentElement, '__l'); + const component = getElementCustomProp(componentElement, '__l'); if (error) { expect(component).toBeUndefined(); diff --git a/src/__test__/component.spec.ts b/src/__test__/component.spec.ts index 31bb53c..ba61bb0 100644 --- a/src/__test__/component.spec.ts +++ b/src/__test__/component.spec.ts @@ -1,7 +1,7 @@ import { component, Component } from '../component'; import reactive from '../core/reactive'; import { directives } from '../core/directive'; -import { getCustomProp } from '../core/utils/customProp'; +import { getElementCustomProp } from '../core/utils/elementCustomProp'; describe('.component', () => { it('should create and mount component properly', () => { @@ -34,7 +34,7 @@ describe('.component', () => { const app = component(state); app.mount(el); - expect(getCustomProp(el, '__l')).toEqual(app); + expect(getElementCustomProp(el, '__l')).toEqual(app); }); it('should register custom directive', () => { diff --git a/src/core/directives/__test__/for.spec.ts b/src/core/directives/__test__/for.spec.ts index ec64fa7..e3c3070 100644 --- a/src/core/directives/__test__/for.spec.ts +++ b/src/core/directives/__test__/for.spec.ts @@ -1,6 +1,6 @@ import { forDirective } from '../for'; import compute from '../../utils/computeExpression'; -import { setCustomProp } from '../../utils/customProp'; +import { setElementCustomProp } from '../../utils/elementCustomProp'; describe('.forDirective', () => { it('should join the state array into HTML', (done) => { @@ -9,7 +9,7 @@ describe('.forDirective', () => { const state = { foo: ['bar', 'bar', 'bar'] }; const data = { value: expression, compute: compute(expression, el), deps: ['foo'] }; - setCustomProp(el, '__l_for_template', '
  • '); + setElementCustomProp(el, '__l_for_template', '
  • '); el.innerHTML = '
  • '; forDirective({ @@ -35,7 +35,7 @@ describe('.forDirective', () => { const state = { foo: ['bar', 'bar', 'bar'] }; const data = { value: expression, compute: compute(expression, el), deps: ['foo'] }; - setCustomProp(el, '__l_for_template', '
  • '); + setElementCustomProp(el, '__l_for_template', '
  • '); el.innerHTML = '
  • '; forDirective({ @@ -57,7 +57,7 @@ describe('.forDirective', () => { const state = { foo: ['bar', 'bar', 'bar'] }; const data = { value: expression, compute: compute(expression, el), deps: ['foo'] }; - setCustomProp(el, '__l_for_template', '
  • '); + setElementCustomProp(el, '__l_for_template', '
  • '); forDirective({ el, @@ -76,8 +76,8 @@ describe('.forDirective', () => { const state = { foo: ['bar', 'bar'] }; const data = { value: expression, compute: compute(expression, el), deps: ['foo'] }; - setCustomProp(el, '__l_for_template', '
  • '); - setCustomProp(el, '__l_for_state', ['bar', 'bar']); + setElementCustomProp(el, '__l_for_template', '
  • '); + setElementCustomProp(el, '__l_for_state', ['bar', 'bar']); el.innerHTML = '
  • '; forDirective({ @@ -97,8 +97,8 @@ describe('.forDirective', () => { const state = { foo: ['bar', 'bar', 'bar'] }; const data = { value: expression, compute: compute(expression, el), deps: ['foo'] }; - setCustomProp(el, '__l_for_template', '
  • '); - setCustomProp(el, '__l_for_state', ['bar', 'bar', 'bar']); + setElementCustomProp(el, '__l_for_template', '
  • '); + setElementCustomProp(el, '__l_for_state', ['bar', 'bar', 'bar']); el.innerHTML = '
  • '; forDirective({ diff --git a/src/core/directives/__test__/if.spec.ts b/src/core/directives/__test__/if.spec.ts index 30b603b..64a6c81 100644 --- a/src/core/directives/__test__/if.spec.ts +++ b/src/core/directives/__test__/if.spec.ts @@ -1,6 +1,6 @@ import { ifDirective } from '../if'; import compute from '../../utils/computeExpression'; -import { getCustomProp } from '../../utils/customProp'; +import { getElementCustomProp } from '../../utils/elementCustomProp'; describe('.ifDirective', () => { it('should conditionally remove element', () => { @@ -22,7 +22,7 @@ describe('.ifDirective', () => { node, }); - expect(getCustomProp(node.el, '__l_if_template')).toEqual(true); + expect(getElementCustomProp(node.el, '__l_if_template')).toEqual(true); expect(node.el.tagName).toEqual('TEMPLATE'); expect(node.el.nextElementSibling).toBeFalsy(); }); @@ -49,7 +49,7 @@ describe('.ifDirective', () => { node, }); - expect(getCustomProp(node.el, '__l_if_template')).toEqual(true); + expect(getElementCustomProp(node.el, '__l_if_template')).toEqual(true); expect(node.el.tagName).toEqual('TEMPLATE'); expect(node.el.nextElementSibling).toBeDefined(); }); @@ -76,7 +76,7 @@ describe('.ifDirective', () => { node, }); - expect(getCustomProp(node.el, '__l_if_template')).toEqual(true); + expect(getElementCustomProp(node.el, '__l_if_template')).toEqual(true); expect(node.el.tagName).toEqual('TEMPLATE'); expect(node.el.nextElementSibling).toBeDefined(); }); diff --git a/src/core/directives/__test__/on.spec.ts b/src/core/directives/__test__/on.spec.ts index 023fdaa..125c093 100644 --- a/src/core/directives/__test__/on.spec.ts +++ b/src/core/directives/__test__/on.spec.ts @@ -2,7 +2,7 @@ import { fireEvent } from '@testing-library/dom'; import { onDirective } from '../on'; import compute from '../../utils/computeExpression'; -import { getCustomProp } from '../../utils/customProp'; +import { getElementCustomProp } from '../../utils/elementCustomProp'; describe('.onDirective', () => { it('should attach click event listener', () => { @@ -20,7 +20,7 @@ describe('.onDirective', () => { }); fireEvent.click(el); - expect(typeof getCustomProp(el, '__l_on_registered')).toEqual('boolean'); + expect(typeof getElementCustomProp(el, '__l_on_registered')).toEqual('boolean'); expect(callback).toBeCalledTimes(1); onDirective({ diff --git a/src/core/utils/__test__/customProp.spec.ts b/src/core/utils/__test__/customProp.spec.ts index 333c609..5b7fd49 100644 --- a/src/core/utils/__test__/customProp.spec.ts +++ b/src/core/utils/__test__/customProp.spec.ts @@ -1,4 +1,4 @@ -import { getCustomProp, setCustomProp } from '../customProp'; +import { getElementCustomProp, setElementCustomProp } from '../elementCustomProp'; describe('.customProp', () => { it('should correctly access custom prop', () => { @@ -7,15 +7,15 @@ describe('.customProp', () => { // @ts-ignore el.__l = 'foo'; - expect(getCustomProp(el, 'innerHTML')).toEqual(''); - expect(getCustomProp(el, '__l')).toEqual('foo'); + expect(getElementCustomProp(el, 'innerHTML')).toEqual(''); + expect(getElementCustomProp(el, '__l')).toEqual('foo'); }); it('should correctly mutate custom prop', () => { const el = document.createElement('div'); - setCustomProp(el, '__l', 'foo'); + setElementCustomProp(el, '__l', 'foo'); - expect(getCustomProp(el, '__l')).toEqual('foo'); + expect(getElementCustomProp(el, '__l')).toEqual('foo'); }); }); diff --git a/src/core/utils/elementCustomProp.ts b/src/core/utils/elementCustomProp.ts index b0aae83..d839d66 100644 --- a/src/core/utils/elementCustomProp.ts +++ b/src/core/utils/elementCustomProp.ts @@ -4,4 +4,5 @@ export const getElementCustomProp = (el: HTMLElement, prop: string) => el[prop]; // @ts-ignore -export const setElementCustomProp = (el: HTMLElement, prop: string, value: any) => (el[prop] = value); +export const setElementCustomProp = (el: HTMLElement, prop: string, value: any) => + (el[prop] = value);