Skip to content

Commit c9c9947

Browse files
committed
Move react to using common tests
1 parent 2f5c6be commit c9c9947

File tree

7 files changed

+100
-364
lines changed

7 files changed

+100
-364
lines changed

libraries/__shared__/tests/src/advanced-tests.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ export default function (
3737
this.weight = 2
3838
const { wc } = await renderComponentWithProperties.call(this)
3939
let data = wc.arr
40-
expect(data).to.eql(['r', 'i', 'o', 't'])
40+
expect(data).to.eql(['c', 'u', 's', 't', 'o', 'm'])
4141
})
4242

4343
it('will pass object data as a property', async function () {
4444
this.weight = 2
4545
const { wc } = await renderComponentWithProperties.call(this)
4646
let data = wc.obj
47-
expect(data).to.eql({org: 'riotjs', repo: 'riot'})
47+
expect(data).to.eql({org: 'webcomponents', repo: 'custom-elements-everywhere'})
4848
})
4949

5050
it('will pass object data to a camelCase-named property', async function () {
@@ -59,47 +59,47 @@ export default function (
5959
describe('events', function () {
6060
it('can declaratively listen to a lowercase DOM event dispatched by a Custom Element', async function () {
6161
this.weight = 2
62-
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
62+
const { wc, click = wc.click } = await renderComponentWithDeclarativeEvent.call(this)
6363
expect(wc).to.exist
6464
let handled = document.querySelector('#lowercase')
6565
expect(handled.textContent).to.eql('false')
66-
wc.click()
66+
click()
6767
expect(handled.textContent).to.eql('true')
6868
})
6969

7070
it('can declaratively listen to a kebab-case DOM event dispatched by a Custom Element', async function () {
7171
this.weight = 1
72-
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
72+
const { wc, click = wc.click } = await renderComponentWithDeclarativeEvent.call(this)
7373
let handled = document.querySelector('#kebab')
7474
expect(handled.textContent).to.eql('false')
75-
wc.click()
75+
click()
7676
expect(handled.textContent).to.eql('true')
7777
})
7878

7979
it('can declaratively listen to a camelCase DOM event dispatched by a Custom Element', async function () {
8080
this.weight = 1
81-
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
81+
const { wc, click = wc.click } = await renderComponentWithDeclarativeEvent.call(this)
8282
let handled = document.querySelector('#camel')
8383
expect(handled.textContent).to.eql('false')
84-
wc.click()
84+
click()
8585
expect(handled.textContent).to.eql('true')
8686
})
8787

8888
it('can declaratively listen to a CAPScase DOM event dispatched by a Custom Element', async function () {
8989
this.weight = 1
90-
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
90+
const { wc, click = wc.click } = await renderComponentWithDeclarativeEvent.call(this)
9191
let handled = document.querySelector('#caps')
9292
expect(handled.textContent).to.eql('false')
93-
wc.click()
93+
click()
9494
expect(handled.textContent).to.eql('true')
9595
})
9696

9797
it('can declaratively listen to a PascalCase DOM event dispatched by a Custom Element', async function () {
9898
this.weight = 1
99-
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
99+
const { wc, click = wc.click } = await renderComponentWithDeclarativeEvent.call(this)
100100
let handled = document.querySelector('#pascal')
101101
expect(handled.textContent).to.eql('false')
102-
wc.click()
102+
click()
103103
expect(handled.textContent).to.eql('true')
104104
})
105105
})

libraries/__shared__/tests/src/basic-tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default function (
7272
const { wc, toggle } = await renderComponentWithDifferentViews.call(this);
7373
expectHasChildren(wc)
7474
toggle()
75-
let dummy = document.querySelector('#dummy')
75+
const dummy = document.querySelector('#dummy')
7676
expect(dummy).to.exist
7777
expect(dummy.textContent).to.eql('Dummy view')
7878
toggle()
@@ -99,18 +99,18 @@ export default function (
9999
this.weight = 3
100100
const { wc } = await renderComponentWithProperties.call(this);
101101
let data = wc.str || wc.getAttribute('str')
102-
expect(data).to.eql('riot')
102+
expect(data).to.eql('custom')
103103
})
104104
})
105105

106106
describe('events', async function () {
107107
it('can imperatively listen to a DOM event dispatched by a Custom Element', async function () {
108108
this.weight = 3
109-
const { wc } = await renderComponentWithImperativeEvent.call(this)
109+
const { wc, click = wc.click } = await renderComponentWithImperativeEvent.call(this)
110110
expect(wc).to.exist
111111
let handled = document.querySelector('#handled')
112112
expect(handled.textContent).to.eql('false')
113-
wc.click()
113+
click()
114114
expect(handled.textContent).to.eql('true')
115115
})
116116
})

libraries/react/karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module.exports = function(config) {
6161
resolve: {
6262
modules: [
6363
path.resolve(__dirname, '../__shared__/webcomponents/src'),
64+
path.resolve(__dirname, '../__shared__/tests/src'),
6465
path.resolve(__dirname, './node_modules')
6566
]
6667
},

libraries/react/src/advanced-tests.js

Lines changed: 25 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,15 @@ import {
3030
ComponentWithDeclarativeEvent
3131
} from "./components";
3232

33+
import tests from 'advanced-tests';
34+
3335
// Setup the test harness. This will get cleaned out with every test.
3436
let app = document.createElement("div");
3537
app.id = "app";
3638
document.body.appendChild(app);
3739
let scratch; // This will hold the actual element under test.
3840

3941
let reactRoot = null;
40-
function render(element) {
41-
act(() => {
42-
reactRoot.render(element);
43-
});
44-
}
4542

4643
before(() => {
4744
window.IS_REACT_ACT_ENVIRONMENT = true;
@@ -68,150 +65,32 @@ afterEach(function() {
6865
});
6966
});
7067

71-
describe("advanced support", function() {
7268

73-
describe("attributes and properties", function() {
74-
it("will pass array data as a property", function() {
75-
this.weight = 2;
76-
let root;
77-
render(
78-
<ComponentWithProperties
79-
ref={(current) => {
80-
root = current;
81-
}}
82-
/>
83-
);
84-
let wc = root.wc;
85-
let data = wc.arr;
86-
expect(data).to.eql(["R", "e", "a", "c", "t"]);
87-
});
88-
89-
it("will pass object data as a property", function() {
90-
this.weight = 2;
91-
let root;
92-
render(
93-
<ComponentWithProperties
94-
ref={(current) => {
95-
root = current;
96-
}}
97-
/>
98-
);
99-
let wc = root.wc;
100-
let data = wc.obj;
101-
expect(data).to.eql({ org: "facebook", repo: "react" });
102-
});
103-
104-
it("will pass object data to a camelCase-named property", function() {
105-
this.weight = 2;
106-
let root;
107-
render(
108-
<ComponentWithProperties
109-
ref={(current) => {
110-
root = current;
111-
}}
112-
/>
113-
);
114-
let wc = root.wc;
115-
let data = wc.camelCaseObj;
116-
expect(data).to.eql({ label: "passed" });
117-
});
69+
function render(Component) {
70+
let root;
71+
act(() => {
72+
reactRoot.render(
73+
<Component
74+
ref={(current) => {
75+
root = current;
76+
}}
77+
/>
78+
);
11879
});
80+
return {wc: root.wc, root}
81+
}
11982

120-
describe("events", function() {
121-
it("can declaratively listen to a lowercase DOM event dispatched by a Custom Element", function() {
122-
this.weight = 2;
123-
let root;
124-
render(
125-
<ComponentWithDeclarativeEvent
126-
ref={(current) => {
127-
root = current;
128-
}}
129-
/>
130-
);
131-
let wc = root.wc;
132-
let handled = root.lowercase;
133-
expect(handled.textContent).to.eql("false");
134-
act(() => {
135-
wc.click();
136-
});
137-
expect(handled.textContent).to.eql("true");
138-
});
139-
140-
it("can declaratively listen to a kebab-case DOM event dispatched by a Custom Element", function() {
141-
this.weight = 1;
142-
let root;
143-
render(
144-
<ComponentWithDeclarativeEvent
145-
ref={(current) => {
146-
root = current;
147-
}}
148-
/>
149-
);
150-
let wc = root.wc;
151-
let handled = root.kebab;
152-
expect(handled.textContent).to.eql("false");
153-
act(() => {
154-
wc.click();
155-
});
156-
expect(handled.textContent).to.eql("true");
157-
});
158-
159-
it("can declaratively listen to a camelCase DOM event dispatched by a Custom Element", function() {
160-
this.weight = 1;
161-
let root;
162-
render(
163-
<ComponentWithDeclarativeEvent
164-
ref={(current) => {
165-
root = current;
166-
}}
167-
/>
168-
);
169-
let wc = root.wc;
170-
let handled = root.camel;
171-
expect(handled.textContent).to.eql("false");
172-
act(() => {
173-
wc.click();
174-
});
175-
expect(handled.textContent).to.eql("true");
176-
});
177-
178-
it("can declaratively listen to a CAPScase DOM event dispatched by a Custom Element", function() {
179-
this.weight = 1;
180-
let root;
181-
render(
182-
<ComponentWithDeclarativeEvent
183-
ref={(current) => {
184-
root = current;
185-
}}
186-
/>
187-
);
188-
let wc = root.wc;
189-
let handled = root.caps;
190-
expect(handled.textContent).to.eql("false");
191-
act(() => {
192-
wc.click();
193-
});
194-
expect(handled.textContent).to.eql("true");
195-
});
196-
197-
it("can declaratively listen to a PascalCase DOM event dispatched by a Custom Element", function() {
198-
this.weight = 1;
199-
let root;
200-
render(
201-
<ComponentWithDeclarativeEvent
202-
ref={(current) => {
203-
root = current;
204-
}}
205-
/>
206-
);
207-
let wc = root.wc;
208-
let handled = root.pascal;
209-
expect(handled.textContent).to.eql("false");
83+
tests({
84+
renderComponentWithProperties() {
85+
return render(ComponentWithProperties);
86+
},
87+
renderComponentWithDeclarativeEvent() {
88+
const { wc, root } = render(ComponentWithDeclarativeEvent)
89+
function click() {
21090
act(() => {
21191
wc.click();
21292
});
213-
expect(handled.textContent).to.eql("true");
214-
});
215-
});
216-
217-
});
93+
}
94+
return { wc, root, click }
95+
}
96+
})

0 commit comments

Comments
 (0)