-
Notifications
You must be signed in to change notification settings - Fork 770
/
context.spec.tsx
75 lines (71 loc) · 2.42 KB
/
context.spec.tsx
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
import { newSpecPage } from '@stencil/core/testing';
import { Component, Prop, readTask, writeTask } from '@stencil/core';
import { QueueApi } from '../../declarations';
describe('context', () => {
it('should return default values of context', async () => {
@Component({
tag: 'cmp-a',
})
class CmpA {
@Prop({ context: 'window' }) win: Window;
@Prop({ context: 'document' }) doc: Document;
@Prop({ context: 'isServer' }) isServer: boolean;
@Prop({ context: 'isPrerender' }) isPrerender: boolean;
@Prop({ context: 'isClient' }) isClient: boolean;
@Prop({ context: 'resourcesUrl' }) resourcesUrl: string;
@Prop({ context: 'publicPath' }) publicPath: string;
@Prop({ context: 'queue' }) queue: QueueApi;
}
const { win, doc, rootInstance } = await newSpecPage({
components: [CmpA],
html: `<cmp-a></cmp-a>`,
});
expect(rootInstance.win).toEqual(win);
expect(rootInstance.doc).toEqual(doc);
expect(rootInstance.isServer).toEqual(false);
expect(rootInstance.isPrerender).toEqual(false);
expect(rootInstance.isClient).toEqual(true);
expect(rootInstance.resourcesUrl).toEqual('/');
expect(rootInstance.publicPath).toEqual('/');
expect(rootInstance.queue.write).toEqual(writeTask);
expect(rootInstance.queue.read).toEqual(readTask);
expect(rootInstance.queue.tick).not.toBeUndefined();
});
it('should replace default values of context', async () => {
@Component({
tag: 'cmp-a',
})
class CmpA {
@Prop({ context: 'resourcesUrl' }) resourcesUrl: boolean;
@Prop({ context: 'publicPath' }) publicPath: boolean;
}
const { rootInstance } = await newSpecPage({
components: [CmpA],
html: `<cmp-a></cmp-a>`,
context: {
resourcesUrl: '/blabla',
publicPath: '/blubblub',
},
});
expect(rootInstance.resourcesUrl).toEqual('/blabla');
expect(rootInstance.publicPath).toEqual('/blubblub');
});
it('should extend context', async () => {
@Component({
tag: 'cmp-a',
})
class CmpA {
@Prop({ context: 'value' }) value: number;
@Prop({ context: 'unknown' }) unknown: any;
}
const { rootInstance } = await newSpecPage({
components: [CmpA],
html: `<cmp-a></cmp-a>`,
context: {
value: 1234,
},
});
expect(rootInstance.value).toEqual(1234);
expect(rootInstance.unknown).toEqual(undefined);
});
});