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
Showing
5 changed files
with
94 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
require: [ | ||
'@babel/register', | ||
'@babel/polyfill', | ||
'./helpers/enzyme.js', | ||
'./helpers/browser-env.js', | ||
], | ||
}; |
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,3 @@ | ||
import browserEnv from 'browser-env'; | ||
|
||
browserEnv(); |
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,4 @@ | ||
import Enzyme from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); |
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,55 @@ | ||
import React, { useState } from 'react'; | ||
import test from 'ava'; | ||
import { mount } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
import root from './'; | ||
|
||
test('It should be able to create the shadow boundary;', t => { | ||
const wrapper = mount(<root.div>Hello Adam!</root.div>); | ||
t.truthy(wrapper.getDOMNode().shadowRoot); | ||
t.is(wrapper.getDOMNode().shadowRoot.innerHTML, 'Hello Adam!'); | ||
}); | ||
|
||
test('It should be able to register events in the shadow boundary;', t => { | ||
const spies = { onClick: sinon.spy() }; | ||
const wrapper = mount( | ||
<root.div> | ||
<div onClick={() => spies.onClick('Maria')}>Hello Maria</div> | ||
</root.div>, | ||
); | ||
const node = wrapper.getDOMNode().shadowRoot.querySelector('div'); | ||
node.click(); | ||
t.is(spies.onClick.callCount, 1); | ||
t.true(spies.onClick.calledWith('Maria')); | ||
}); | ||
|
||
test('It should be able to applie styles to the shadow boundary components;', t => { | ||
const wrapper = mount( | ||
<root.div> | ||
Hello Adam! | ||
<style type="text/css">{`* { border: 1px solid red; }`}</style> | ||
</root.div>, | ||
); | ||
const node = wrapper.getDOMNode().shadowRoot.querySelector('style'); | ||
t.is(node.innerHTML, '* { border: 1px solid red; }'); | ||
}); | ||
|
||
test('It should be able re-render the component tree from the event handlers;', t => { | ||
function Name() { | ||
const [name, setName] = useState(null); | ||
return ( | ||
<> | ||
{name && <div>Hello {name}!</div>} | ||
<root.section> | ||
<button onClick={() => setName('Adam')}>Change Name</button> | ||
</root.section> | ||
</> | ||
); | ||
} | ||
|
||
const wrapper = mount(<Name />); | ||
const node = wrapper.getDOMNode().shadowRoot.querySelector('button'); | ||
node.click(); | ||
wrapper.update(); | ||
t.is(wrapper.find('div').text(), 'Hello Adam!'); | ||
}); |