forked from IDuxFE/idux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(comp: typography): modify code and test (IDuxFE#196)
- Loading branch information
1 parent
d8bb853
commit 0c36894
Showing
5 changed files
with
126 additions
and
140 deletions.
There are no files selected for viewing
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,42 @@ | ||
import { addClass, hasClass, off, on, removeClass } from '../dom' | ||
|
||
describe('dom.ts', () => { | ||
let testElement: HTMLDivElement | ||
|
||
beforeEach(() => { | ||
testElement = document.createElement('div') | ||
}) | ||
|
||
test('event listener', () => { | ||
const log = jest.spyOn(console, 'log').mockImplementation(() => {}) | ||
const listener = () => console.log('click') | ||
on(testElement, 'click', listener) | ||
testElement.click() | ||
expect(log).toBeCalled() | ||
expect(log).toBeCalledTimes(1) | ||
off(testElement, 'click', listener) | ||
expect(log).toBeCalledTimes(1) | ||
}) | ||
|
||
test('hasClass work', () => { | ||
addClass(testElement, 'test-class') | ||
expect(hasClass(testElement, 'test-class')).toBeTruthy() | ||
expect(hasClass(testElement, '')).toBeFalsy() | ||
}) | ||
|
||
test('add class work', () => { | ||
expect(Array.from(testElement.classList)).toEqual([]) | ||
addClass(testElement, 'test-class') | ||
expect(Array.from(testElement.classList)).toEqual(['test-class']) | ||
addClass(testElement, ['test-class', 'test-class-2']) | ||
expect(Array.from(testElement.classList)).toEqual(['test-class', 'test-class-2']) | ||
}) | ||
|
||
test('remove class work', () => { | ||
addClass(testElement, 'test-class') | ||
removeClass(testElement, []) | ||
expect(Array.from(testElement.classList)).toEqual(['test-class']) | ||
removeClass(testElement, 'test-class') | ||
expect(Array.from(testElement.classList)).toEqual([]) | ||
}) | ||
}) |
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
2 changes: 1 addition & 1 deletion
2
packages/components/typography/__tests__/__snapshots__/typography.spec.ts.snap
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`typography.ts render work 1`] = `"<article class=\\" ix-typography\\"><h1 class=\\" ix-typography\\">Title</h1><p class=\\" ix-typography\\"> In the process of internal desktop applications development, many different design specs and implementations would be involved, which might cause designers and developers difficulties and duplication and reduce the efficiency of development. </p><div class=\\" ix-typography\\"><ul><li><a href=\\"/docs/spec/proximity\\">Principles</a></li><li><a href=\\"/docs/pattern/navigation\\">Patterns</a></li><li><a href=\\"/docs/resource/download\\">Resource Download</a></li></ul></div><p class=\\" ix-typography\\"> Press <span class=\\" ix-typography\\"><kbd>Esc</kbd></span> to exist... </p></article>"`; | ||
exports[`typography.ts render work 1`] = `"<p class=\\"ix-typography\\">Paragraph</p>"`; |
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