-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathadvanced-tests.js
163 lines (149 loc) · 5.84 KB
/
advanced-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* @license
* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { TestBed } from "@angular/core/testing";
import { By } from "@angular/platform-browser";
import { expect } from "chai";
import {
ComponentWithoutChildren,
ComponentWithChildren,
ComponentWithChildrenRerender,
ComponentWithDifferentViews,
ComponentWithProperties,
ComponentWithInheritance,
ComponentWithUnregistered,
ComponentWithImperativeEvent,
ComponentWithDeclarativeEvent
} from "./components";
beforeEach(function() {
TestBed.configureTestingModule({
declarations: [
ComponentWithoutChildren,
ComponentWithChildren,
ComponentWithChildrenRerender,
ComponentWithDifferentViews,
ComponentWithProperties,
ComponentWithUnregistered,
ComponentWithImperativeEvent,
ComponentWithDeclarativeEvent
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
});
describe("advanced support", function() {
describe("attributes and properties", function() {
it("will pass array data as a property", function() {
this.weight = 2;
let fixture = TestBed.createComponent(ComponentWithProperties);
fixture.detectChanges();
let root = fixture.debugElement.nativeElement;
let wc = root.querySelector("#wc");
let data = wc.arr;
expect(data).to.eql(["A", "n", "g", "u", "l", "a", "r"]);
});
it("will pass object data as a property", function() {
this.weight = 2;
let fixture = TestBed.createComponent(ComponentWithProperties);
fixture.detectChanges();
let root = fixture.debugElement.nativeElement;
let wc = root.querySelector("#wc");
let data = wc.obj;
expect(data).to.eql({ org: "angular", repo: "angular" });
});
it("will pass object data to a camelCase-named property", function() {
this.weight = 2;
let fixture = TestBed.createComponent(ComponentWithProperties);
fixture.detectChanges();
let root = fixture.debugElement.nativeElement;
let wc = root.querySelector("#wc");
let data = wc.camelCaseObj;
expect(data).to.eql({ label: "passed" });
});
it("will pass object data to inherited properties", function() {
this.weight = 2;
let fixture = TestBed.createComponent(ComponentWithInheritance);
fixture.detectChanges();
let root = fixture.debugElement.nativeElement;
let wc = root.querySelector("#wc");
expect(wc.arr).to.eql(["A", "n", "g", "u", "l", "a", "r"]);
expect(wc.obj).to.eql({ org: "angular", repo: "angular" });
expect(wc.camelCaseObj).to.eql({ label: "passed" });
});
});
describe("events", function() {
it("can declaratively listen to a lowercase DOM event dispatched by a Custom Element", function() {
this.weight = 2;
let fixture = TestBed.createComponent(ComponentWithDeclarativeEvent);
fixture.detectChanges();
let root = fixture.debugElement.nativeElement;
let wc = root.querySelector("#wc");
let handled = root.querySelector("#lowercase");
expect(handled.textContent).to.eql("false");
wc.click();
fixture.detectChanges();
expect(handled.textContent).to.eql("true");
});
it("can declaratively listen to a kebab-case DOM event dispatched by a Custom Element", function() {
this.weight = 1;
let fixture = TestBed.createComponent(ComponentWithDeclarativeEvent);
fixture.detectChanges();
let root = fixture.debugElement.nativeElement;
let wc = root.querySelector("#wc");
let handled = root.querySelector("#kebab");
expect(handled.textContent).to.eql("false");
wc.click();
fixture.detectChanges();
expect(handled.textContent).to.eql("true");
});
it("can declaratively listen to a camelCase DOM event dispatched by a Custom Element", function() {
this.weight = 1;
let fixture = TestBed.createComponent(ComponentWithDeclarativeEvent);
fixture.detectChanges();
let root = fixture.debugElement.nativeElement;
let wc = root.querySelector("#wc");
let handled = root.querySelector("#camel");
expect(handled.textContent).to.eql("false");
wc.click();
fixture.detectChanges();
expect(handled.textContent).to.eql("true");
});
it("can declaratively listen to a CAPScase DOM event dispatched by a Custom Element", function() {
this.weight = 1;
let fixture = TestBed.createComponent(ComponentWithDeclarativeEvent);
fixture.detectChanges();
let root = fixture.debugElement.nativeElement;
let wc = root.querySelector("#wc");
let handled = root.querySelector("#caps");
expect(handled.textContent).to.eql("false");
wc.click();
fixture.detectChanges();
expect(handled.textContent).to.eql("true");
});
it("can declaratively listen to a PascalCase DOM event dispatched by a Custom Element", function() {
this.weight = 1;
let fixture = TestBed.createComponent(ComponentWithDeclarativeEvent);
fixture.detectChanges();
let root = fixture.debugElement.nativeElement;
let wc = root.querySelector("#wc");
let handled = root.querySelector("#pascal");
expect(handled.textContent).to.eql("false");
wc.click();
fixture.detectChanges();
expect(handled.textContent).to.eql("true");
});
});
});