-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(esl-mixin-element): major fix for nested hierarchy mixin disconne…
…ction Closes: #2505
- Loading branch information
Showing
3 changed files
with
160 additions
and
82 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/modules/esl-mixin-element/test/mixin.prototype.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import {ESLMixinElement} from '../ui/esl-mixin-element'; | ||
|
||
describe('ESLMixinElement.prototype implements all required ESLComponent API methods', () => { | ||
class CTestMixin extends ESLMixinElement { | ||
static override is = 'c-test'; | ||
} | ||
|
||
let $el: CTestMixin; | ||
|
||
const $host = document.createElement('div'); | ||
$host.toggleAttribute(CTestMixin.is, true); | ||
|
||
beforeAll(async () => { | ||
document.body.appendChild($host); | ||
CTestMixin.register(); | ||
|
||
await Promise.resolve(); | ||
$el = CTestMixin.get($host) as CTestMixin; | ||
}); | ||
|
||
describe('ESLMixinElement.prototype.$$attr persist and correct', () => { | ||
const attrName = 'test-attr'; | ||
const attrNameBool = 'test-attr-bool'; | ||
|
||
test('should return the initial attribute value', () => { | ||
const val = $host.getAttribute(attrName); | ||
expect($el.$$attr(attrName)).toBe(val); | ||
}); | ||
|
||
test('should set the attribute value and return the previous value', () => { | ||
expect($el.$$attr(attrName, 'test')).toBe(null); | ||
expect($el.$$attr(attrName)).toBe('test'); | ||
}); | ||
|
||
test('should set and return an empty string for boolean true', () => { | ||
expect($el.$$attr(attrNameBool, true)).toBe(null); | ||
expect($el.$$attr(attrNameBool)).toBe(''); | ||
}); | ||
|
||
test('should set and return null for removed attribute', () => { | ||
expect($el.$$attr(attrNameBool, false)).toBe(''); | ||
expect($el.$$attr(attrNameBool)).toBe(null); | ||
}); | ||
}); | ||
|
||
describe('ESLMixinElement.prototype.$$cls persist and correct', () => { | ||
test('should return false when class does not exist', () => expect($el.$$cls('a')).toBe(false)); | ||
|
||
test('should return true when class exists', () => { | ||
$host.className = 'a b'; | ||
expect($el.$$cls('a')).toBe(true); | ||
expect($el.$$cls('a b')).toBe(true); | ||
}); | ||
|
||
test('should add the class when setting to true', () => { | ||
$host.className = ''; | ||
$el.$$cls('a', true); | ||
$el.$$cls('b', true); | ||
expect($host.className).toBe('a b'); | ||
}); | ||
|
||
test('should remove the class when setting to false', () => { | ||
$host.className = 'a b'; | ||
expect($el.$$cls('a b', false)).toBe(false); | ||
expect($host.className).toBe(''); | ||
}); | ||
}); | ||
|
||
test('ESLMixinElement.prototype.$$fire persist and correct', () => { | ||
const eventName = 'testevent'; | ||
$host.dispatchEvent = jest.fn(); | ||
$el.$$fire(eventName); | ||
|
||
expect($host.dispatchEvent).lastCalledWith(expect.objectContaining({type: eventName, cancelable: true, bubbles: true})); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters