-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathstyle-warnings-test.ts
81 lines (63 loc) · 2.29 KB
/
style-warnings-test.ts
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
/* eslint-disable @typescript-eslint/no-extraneous-class */
import type { GlobalContext } from '@glimmer/global-context';
import { testOverrideGlobalContext } from '@glimmer/global-context';
import { jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests';
import { assert } from './support';
let warnings = 0;
let originalContext: GlobalContext | null;
class StyleWarningsTest extends RenderTest {
static suiteName = 'Style attributes';
beforeEach() {
warnings = 0;
originalContext =
testOverrideGlobalContext?.({
warnIfStyleNotTrusted() {
warnings++;
},
getProp(obj, key) {
return (obj as Record<string, unknown>)[key];
},
}) ?? null;
}
afterEach() {
testOverrideGlobalContext?.(originalContext);
}
@test
'Standard element with static style and element modifier does not give you a warning'() {
this.registerModifier('foo', class {});
this.render('<button style="display: flex" {{foo}}>click me</button>', {});
assert.strictEqual(warnings, 0);
}
@test
'Standard element with dynamic style and element modifier gives you 1 warning'() {
this.registerModifier('foo', class {});
this.render('<button style={{this.dynAttr}} {{foo}}>click me</button>', {
dynAttr: 'display:flex',
});
assert.strictEqual(warnings, 1);
}
@test
'using a static inline style on an element does not give you a warning'() {
this.render(`<div style="background: red">Thing</div>`, {});
assert.strictEqual(warnings, 0);
this.assertHTML('<div style="background: red">Thing</div>', 'initial render');
}
@test
'triple curlies are trusted'() {
this.render(`<div foo={{this.foo}} style={{{this.styles}}}>Thing</div>`, {
styles: 'background: red',
});
assert.strictEqual(warnings, 0);
this.assertHTML('<div style="background: red">Thing</div>', 'initial render');
}
@test
'using a static inline style on an namespaced element does not give you a warning'() {
this.render(`<svg xmlns:svg="http://www.w3.org/2000/svg" style="background: red" />`, {});
assert.strictEqual(warnings, 0);
this.assertHTML(
'<svg xmlns:svg="http://www.w3.org/2000/svg" style="background: red"></svg>',
'initial render'
);
}
}
jitSuite(StyleWarningsTest);