-
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.
- Loading branch information
Sebastian Klingler
committed
Jun 9, 2018
1 parent
b303795
commit 9de748f
Showing
7 changed files
with
110 additions
and
27 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
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
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,67 @@ | ||
import { h } from 'snabbdom'; | ||
import { VNode } from 'snabbdom/vnode'; | ||
import { style } from 'typestyle'; | ||
import * as client from '../src/client'; | ||
import * as utils from '../src/utils'; | ||
import * as mocks from './mocks'; | ||
|
||
jest.mock('typestyle'); | ||
|
||
describe('removeElement', () => { | ||
|
||
it('removes an element given a selector', () => { | ||
|
||
const element = document.createElement('style'); | ||
element.id = 'styles'; | ||
document.head.appendChild(element); | ||
|
||
client.removeElement(mocks.styleElementSelector()); | ||
expect(document.head.contains(element)).toBe(false); | ||
}); | ||
|
||
it('doesn\'t error when not given a selector', () => { | ||
client.removeElement(); | ||
}); | ||
}); | ||
|
||
describe('makeDomUpdater', () => { | ||
it('calls updateVNode when passed a VNode with an element', () => { | ||
utils.updateVNode = jest.fn(); | ||
client.makeDomUpdater()(mocks.vNodeWithElm(), mocks.vNodeWithElm(); | ||
expect(utils.updateVNode.mock.calls.length).toBe(1); | ||
}); | ||
|
||
it('does not call updateVNode when create is passed a VNode without an element', () => { | ||
utils.updateVNode = jest.fn(); | ||
client.makeDomUpdater()(mocks.vNode(), mocks.vNode(); | ||
expect(utils.updateVNode.mock.calls.length).toBe(0); | ||
}); | ||
|
||
it('passes removeElement the style element selector when create is called', () => { | ||
client.removeElement = jest.fn(); | ||
client.makeDomUpdater(mocks.styleElementSelector())(mocks.vNode(), mocks.vNode(); | ||
expect(client.removeElement.mock.calls.length).toBe(1); | ||
expect(client.removeElement.mock.calls[0][0]).toBe(mocks.styleElementSelector()); | ||
}); | ||
|
||
}); | ||
|
||
describe('makeModule', () => { | ||
|
||
const module; | ||
|
||
beforeEach(() => { | ||
module = client.makeModule(mocks.styleElementSelector()); | ||
}); | ||
|
||
it('returns a module that calls that performs the same function on create and update', () => { | ||
expect(module.update).toEqual(module.create); | ||
}); | ||
|
||
it('calls makeDomUpdater with the styleElementSelector', () => { | ||
const spy = jest.fn(); | ||
client.makeDomUpdater = () => spy; | ||
module.create(mocks.vNodeWithElm(), mocks.vNodeWithElm()); | ||
expect(spy.mock.calls.length).toBe(1); | ||
}); | ||
}); |
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,25 @@ | ||
import { h } from 'snabbdom'; | ||
|
||
export const styleElementSelector = () => '#styles'; | ||
|
||
export const css = () => ({ | ||
color: 'blue' | ||
}); | ||
|
||
export const oldClassName = () => 'test'; | ||
|
||
export const vNode = () => h('div', { | ||
css: css(), | ||
props: { | ||
className: oldClassName() | ||
} | ||
}); | ||
|
||
export const vNodeWithElm = () => { | ||
const node = vNode(); | ||
node.elm = { | ||
setAttribute: jest.fn(); | ||
}; | ||
|
||
return node; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"extends": "tslint:recommended", | ||
"rules": { | ||
"interface-name": [false], | ||
"quotemark": [true, "single"], | ||
"interface-name": [false] | ||
"trailing-comma": [true, {"multiline": "never", "singleline": "never"}] | ||
} | ||
} |