-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathapi-doc.test.ts
4626 lines (4140 loc) · 98.8 KB
/
api-doc.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { expectType } from 'tsd'
// Test case from `Animation`
{
Page({
animation: {} as WechatMiniprogram.Animation,
data: {
animationData: {},
},
onShow() {
const animation = wx.createAnimation({
duration: 1000,
timingFunction: 'ease',
})
this.animation = animation
animation
.scale(2, 2)
.rotate(45)
.step()
this.setData({
animationData: animation.export(),
})
setTimeout(() => {
animation.translate(30).step()
this.setData({
animationData: animation.export(),
})
}, 1000)
},
rotateAndScale() {
// 旋转同时放大
this.animation
.rotate(45)
.scale(2, 2)
.step()
this.setData({
animationData: this.animation.export(),
})
},
rotateThenScale() {
// 先旋转后放大
this.animation.rotate(45).step()
this.animation.scale(2, 2).step()
this.setData({
animationData: this.animation.export(),
})
},
rotateAndScaleThenTranslate() {
// 先旋转同时放大,然后平移
this.animation
.rotate(45)
.scale(2, 2)
.step()
this.animation.translate(100, 100).step({ duration: 1000 })
this.setData({
animationData: this.animation.export(),
})
},
})
}
// Test case from `AudioContext`
{
// audio.js
Page({
audioCtx: {} as WechatMiniprogram.AudioContext,
onReady() {
// 使用 wx.createAudioContext 获取 audio 上下文 context
this.audioCtx = wx.createAudioContext('myAudio')
this.audioCtx.setSrc(
'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46',
)
this.audioCtx.play()
},
data: {
src: '',
},
audioPlay() {
this.audioCtx.play()
},
audioPause() {
this.audioCtx.pause()
},
audio14() {
this.audioCtx.seek(14)
},
audioStart() {
this.audioCtx.seek(0)
},
})
}
// Test case from `BackgroundAudioManager`
{
const backgroundAudioManager = wx.getBackgroundAudioManager()
backgroundAudioManager.title = '此时此刻'
backgroundAudioManager.epname = '此时此刻'
backgroundAudioManager.singer = '许巍'
backgroundAudioManager.coverImgUrl =
'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'
// 设置了 src 之后会自动播放
backgroundAudioManager.src =
'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
}
// Test case from `CameraContext.onCameraFrame`
{
const context = wx.createCameraContext()
const listener = context.onCameraFrame(frame => {
expectType<ArrayBuffer>(frame.data)
expectType<number>(frame.width)
expectType<number>(frame.height)
})
listener.start()
}
// Test case from `CanvasGradient.addColorStop`
{
const ctx = wx.createCanvasContext('myCanvas')
// Create circular gradient
const grd = ctx.createLinearGradient(30, 10, 120, 10)
grd.addColorStop(0, 'red')
grd.addColorStop(0.16, 'orange')
grd.addColorStop(0.33, 'yellow')
grd.addColorStop(0.5, 'green')
grd.addColorStop(0.66, 'cyan')
grd.addColorStop(0.83, 'blue')
grd.addColorStop(1, 'purple')
// Fill with gradient
ctx.setFillStyle(grd)
ctx.fillRect(10, 10, 150, 80)
ctx.draw()
}
// Test case from `DownloadTask`
{
const downloadTask = wx.downloadFile({
url: 'http://example.com/audio/123', // 仅为示例,并非真实的资源
success(res) {
wx.playVoice({
filePath: res.tempFilePath,
})
},
})
downloadTask.onProgressUpdate(res => {
// 下载进度
expectType<number>(res.progress)
// 已经下载的数据长度
expectType<number>(res.totalBytesWritten)
// 预期需要下载的数据总长度
expectType<number>(res.totalBytesExpectedToWrite)
})
downloadTask.abort() // 取消下载任务
}
// Test case from `InnerAudioContext`
{
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src =
'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError(res => {
expectType<string>(res.errMsg)
res.errCode
})
}
// Test case from `NodesRef.boundingClientRect`
{
Page({
getRect() {
wx.createSelectorQuery()
.select('#the-id')
.boundingClientRect(function(rect) {
rect.id // 节点的ID
rect.dataset // 节点的dataset
rect.left // 节点的左边界坐标
rect.right // 节点的右边界坐标
rect.top // 节点的上边界坐标
rect.bottom // 节点的下边界坐标
rect.width // 节点的宽度
rect.height // 节点的高度
})
.exec()
},
getAllRects() {
// FIXME:
// wx.createSelectorQuery().selectAll('.a-class').boundingClientRect(function(rects) {
// rects.forEach(function(rect) {
// rect.id // 节点的ID
// rect.dataset // 节点的dataset
// rect.left // 节点的左边界坐标
// rect.right // 节点的右边界坐标
// rect.top // 节点的上边界坐标
// rect.bottom // 节点的下边界坐标
// rect.width // 节点的宽度
// rect.height // 节点的高度
// })
// }).exec()
},
})
}
// Test case from `NodesRef.context`
{
Page({
getContext() {
wx.createSelectorQuery()
.select('.the-video-class')
.context(function(res) {
const context = res.context as WechatMiniprogram.VideoContext
context.seek(0)
})
.exec()
},
})
}
// Test case from `NodesRef.fields`
{
Page({
getFields() {
wx.createSelectorQuery()
.select('#the-id')
.fields(
{
dataset: true,
size: true,
scrollOffset: true,
properties: ['scrollX', 'scrollY'],
computedStyle: ['margin', 'backgroundColor'],
context: true,
},
function(res) {
res.dataset // 节点的dataset
res.width // 节点的宽度
res.height // 节点的高度
res.scrollLeft // 节点的水平滚动位置
res.scrollTop // 节点的竖直滚动位置
res.scrollX // 节点 scroll-x 属性的当前值
res.scrollY // 节点 scroll-y 属性的当前值
// 此处返回指定要返回的样式名
res.margin
res.backgroundColor
res.context // 节点对应的 Context 对象
},
)
.exec()
},
})
}
// Test case from `NodesRef.node`
{
Page({
getNode() {
wx.createSelectorQuery()
.select('.canvas')
.node(function(res) {
const canvas = res.node as WechatMiniprogram.Canvas
canvas
})
.exec()
},
})
}
// Test case from `NodesRef.scrollOffset`
{
Page({
getScrollOffset() {
wx.createSelectorQuery()
.selectViewport()
.scrollOffset(function(res) {
res.id // 节点的ID
res.dataset // 节点的dataset
res.scrollLeft // 节点的水平滚动位置
res.scrollTop // 节点的竖直滚动位置
})
.exec()
},
})
}
// Test case from `RecorderManager`
{
const recorderManager = wx.getRecorderManager()
recorderManager.onStart(() => {
console.log('recorder start')
})
recorderManager.onPause(() => {
console.log('recorder pause')
})
recorderManager.onStop(res => {
console.log('recorder stop', res)
const { tempFilePath } = res
expectType<string>(tempFilePath)
})
recorderManager.onFrameRecorded(res => {
const { frameBuffer } = res
expectType<number>(frameBuffer.byteLength)
console.log('frameBuffer.byteLength', frameBuffer.byteLength)
})
recorderManager.start({
duration: 10000,
sampleRate: 44100,
numberOfChannels: 1,
encodeBitRate: 192000,
format: 'aac',
frameSize: 50,
})
}
// Test case from `RequestTask`
{
const requestTask = wx.request({
url: 'test.php', // 仅为示例,并非真实的接口地址
data: {
x: '',
y: '',
},
header: {
'content-type': 'application/json',
},
success(res) {
console.log(res.data)
},
})
requestTask.abort() // 取消请求任务
}
// Test case from `SelectorQuery.in`
{
Component({
methods: {
queryMultipleNodes() {
const query = wx.createSelectorQuery().in(this)
query
.select('#the-id')
.boundingClientRect(function(res) {
res.top // 这个组件内 #the-id 节点的上边界坐标
})
.exec()
},
},
})
}
// Test case from `UpdateManager`
{
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function(res) {
// 请求完新版本信息的回调
expectType<boolean>(res.hasUpdate)
})
updateManager.onUpdateReady(function() {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success(res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
},
})
})
updateManager.onUpdateFailed(function() {
// 新版本下载失败
})
}
// Test case from `UploadTask`
{
const uploadTask = wx.uploadFile({
url: 'http://example.weixin.qq.com/upload', // 仅为示例,非真实的接口地址
filePath: '',
name: 'file',
formData: {
user: 'test',
},
success(res) {
expectType<string>(res.data)
},
})
uploadTask.onProgressUpdate(res => {
// 上传进度
expectType<number>(res.progress)
// 已经上传的数据长度
expectType<number>(res.totalBytesSent)
// 预期需要上传的数据总长度
expectType<number>(res.totalBytesExpectedToSend)
})
uploadTask.abort() // 取消上传任务
}
// Test case from `VideoContext`
{
const getRandomColor = () => {
const rgb = []
for (let i = 0; i < 3; ++i) {
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length === 1 ? '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}
Page({
videoContext: {} as WechatMiniprogram.VideoContext,
onReady() {
this.videoContext = wx.createVideoContext('myVideo')
},
inputValue: '',
bindInputBlur(e: any) {
this.inputValue = e.detail.value
},
bindSendDanmu() {
this.videoContext.sendDanmu({
text: this.inputValue,
color: getRandomColor(),
})
},
})
}
// Test case from `Worker.postMessage`
{
const worker = wx.createWorker('')
worker.postMessage({
msg: 'hello from worker',
})
}
// Test case from `Worker`
{
const worker = wx.createWorker('workers/request/index.js') // 文件名指定 worker 的入口文件路径,绝对路径
worker.onMessage(function (res) {
expectType<WechatMiniprogram.WorkerOnMessageListenerResult>(res)
})
// 监听worker被系统回收事件
worker.onProcessKilled(function () {
console.log('worker has been killed')
})
worker.postMessage({
msg: 'hello worker',
})
worker.terminate()
}
// Test case from `wx.addCard`
{
wx.addCard({
cardList: [
{
cardId: '',
cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}',
},
{
cardId: '',
cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}',
},
],
success(res) {
res.cardList.forEach(card => {
expectType<string>(card.cardExt)
expectType<string>(card.cardId)
}) // 卡券添加结果
},
})
}
// Test case from `wx.authorize`
{
// 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
wx.getSetting({
success(res) {
if (!res.authSetting['scope.record']) {
wx.authorize({
scope: 'scope.record',
success() {
// 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
wx.startRecord({
success() {},
})
},
})
}
},
})
}
// Test case from `wx.authorizeForMiniProgram`
{
wx.authorizeForMiniProgram({
scope: 'scope.record',
success() {
// 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
wx.startRecord()
},
})
}
// Test case from `wx.canIUse`
{
// 对象的属性或方法
wx.canIUse('console.log')
wx.canIUse('CameraContext.onCameraFrame')
wx.canIUse('CameraFrameListener.start')
wx.canIUse('Image.src')
// wx接口参数、回调或者返回值
wx.canIUse('openBluetoothAdapter')
wx.canIUse('getSystemInfoSync.return.safeArea.left')
wx.canIUse('getSystemInfo.success.screenWidth')
wx.canIUse('showToast.object.image')
wx.canIUse('onCompassChange.callback.direction')
wx.canIUse('request.object.method.GET')
// 组件的属性
wx.canIUse('live-player')
wx.canIUse('text.selectable')
wx.canIUse('button.open-type.contact')
}
// Test case from `wx.canvasGetImageData`
{
wx.canvasGetImageData({
canvasId: 'myCanvas',
x: 0,
y: 0,
width: 100,
height: 100,
success(res) {
expectType<number>(res.width)
expectType<number>(res.height)
expectType<Uint8ClampedArray>(res.data)
expectType<number>(res.data.length)
},
})
}
// Test case from `wx.checkIsSoterEnrolledInDevice`
{
wx.checkIsSoterEnrolledInDevice({
checkAuthMode: 'fingerPrint',
success(res) {
expectType<boolean>(res.isEnrolled)
},
})
}
// Test case from `wx.checkIsSupportSoterAuthentication`
{
wx.checkIsSupportSoterAuthentication({
success(res) {
res.supportMode = [] // 不具备任何被SOTER支持的生物识别方式
res.supportMode = ['fingerPrint'] // 只支持指纹识别
res.supportMode = ['fingerPrint', 'facial'] // 支持指纹识别和人脸识别
},
})
}
// Test case from `wx.checkSession`
{
wx.checkSession({
success() {
// session_key 未过期,并且在本生命周期一直有效
},
fail() {
// session_key 已经失效,需要重新执行登录流程
wx.login() // 重新登录
},
})
}
// Test case from `wx.chooseAddress`
{
wx.chooseAddress({
success(res) {
expectType<string>(res.userName)
expectType<string>(res.postalCode)
expectType<string>(res.provinceName)
expectType<string>(res.cityName)
expectType<string>(res.countyName)
expectType<string>(res.detailInfo)
expectType<string>(res.nationalCode)
expectType<string>(res.telNumber)
},
})
}
// Test case from `wx.chooseInvoiceTitle`
{
wx.chooseInvoiceTitle({
success() {},
})
}
// Test case from `wx.chooseVideo`
{
wx.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: 'back',
success(res) {
expectType<string>(res.tempFilePath)
},
})
}
// Test case from `wx.clearStorageSync`
{
wx.clearStorage()
}
// Test case from `wx.clearStorage`
{
wx.clearStorage()
}
// Test case from `wx.closeBLEConnection`
{
wx.closeBLEConnection({
deviceId: '',
success(res) {
console.log(res)
},
})
}
// Test case from `wx.closeBluetoothAdapter`
{
wx.closeBluetoothAdapter({
success(res) {
console.log(res)
},
})
}
// Test case from `wx.closeSocket`
{
wx.connectSocket({
url: 'test.php',
})
// 注意这里有时序问题,
// 如果 wx.connectSocket 还没回调 wx.onSocketOpen,而先调用 wx.closeSocket,那么就做不到关闭 WebSocket 的目的。
// 必须在 WebSocket 打开期间调用 wx.closeSocket 才能关闭。
wx.onSocketOpen(function() {
wx.closeSocket()
})
wx.onSocketClose(function(res) {
expectType<number>(res.code)
expectType<string>(res.reason)
console.log('WebSocket 已关闭!')
})
}
// Test case from `wx.compressImage`
{
wx.compressImage({
src: '', // 图片路径
quality: 80, // 压缩质量
})
}
// Test case from `wx.connectSocket`
{
wx.connectSocket({
url: 'wss://example.qq.com',
header: {
'content-type': 'application/json',
},
protocols: ['protocol1'],
})
}
// Test case from `wx.connectWifi`
{
wx.connectWifi({
SSID: '',
password: '',
success(res) {
expectType<string>(res.errMsg)
},
})
}
// Test case from `wx.createBLEConnection`
{
wx.createBLEConnection({
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
deviceId: '',
success(res) {
console.log(res)
},
})
}
// Test case from `wx.createSelectorQuery`
{
const query = wx.createSelectorQuery()
query.select('#the-id').boundingClientRect()
query.selectViewport().scrollOffset()
query.exec(function(res) {
res[0].top // #the-id节点的上边界坐标
res[1].scrollTop // 显示区域的竖直滚动位置
})
}
// Test case from `wx.downloadFile`
{
wx.downloadFile({
url: 'https://example.com/audio/123', // 仅为示例,并非真实的资源
success(res) {
// 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
if (res.statusCode === 200) {
wx.playVoice({
filePath: res.tempFilePath,
})
}
},
})
}
// Test case from `wx.getAccountInfoSync`
{
const accountInfo = wx.getAccountInfoSync()
// 小程序 appId
expectType<string>(accountInfo.miniProgram.appId)
// 插件 appId
expectType<string>(accountInfo.plugin.appId)
// 插件版本号, 'a.b.c' 这样的形式
expectType<string>(accountInfo.plugin.version)
}
// Test case from `wx.getBLEDeviceCharacteristics`
{
wx.getBLEDeviceCharacteristics({
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
deviceId: '',
// 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
serviceId: '',
success(res) {
res.characteristics.forEach(characteristic => {
expectType<boolean>(characteristic.properties.indicate)
expectType<boolean>(characteristic.properties.notify)
expectType<boolean>(characteristic.properties.read)
expectType<boolean>(characteristic.properties.write)
expectType<string>(characteristic.uuid)
})
},
})
}
// Test case from `wx.getBLEDeviceServices`
{
wx.getBLEDeviceServices({
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
deviceId: '',
success(res) {
res.services.forEach(service => {
expectType<string>(service.uuid)
expectType<boolean>(service.isPrimary)
})
},
})
}
// Test case from `wx.getBackgroundAudioPlayerState`
{
wx.getBackgroundAudioPlayerState({
success(res) {
expectType<0 | 1 | 2>(res.status)
expectType<string>(res.dataUrl)
expectType<number>(res.currentPosition)
expectType<number>(res.duration)
expectType<number>(res.downloadPercent)
},
})
}
// Test case from `wx.getBluetoothAdapterState`
{
wx.getBluetoothAdapterState({
success(res) {
console.log(res)
},
})
}
// Test case from `wx.getBluetoothDevices`
{
wx.getBluetoothDevices({
success(res) {
res.devices.forEach(device => {
expectType<ArrayBuffer>(device.advertisData)
})
},
})
}
// Test case from `wx.getClipboardData`
{
wx.getClipboardData({
success(res) {
expectType<string>(res.data)
},
})
}
// Test case from `wx.getConnectedBluetoothDevices`
{
wx.getConnectedBluetoothDevices({
services: ['FEE7'],
success(res) {
res.devices.forEach(device => {
expectType<string>(device.deviceId)
expectType<string>(device.name)
})
},
})
}
// Test case from `wx.getHCEState`
{
wx.getHCEState({
success(res) {
expectType<string>(res.errMsg)
},
})
}
// Test case from `wx.getImageInfo`
{
wx.getImageInfo({
src: 'images/a.jpg',
success(res) {
expectType<number>(res.width)
expectType<number>(res.height)
},
})
wx.chooseImage({
success(res) {
wx.getImageInfo({
src: res.tempFilePaths[0],
success(res) {
expectType<number>(res.width)
expectType<number>(res.height)
},
})
},
})
}
// Test case from `wx.getLogManager`
{
const logger = wx.getLogManager({ level: 1 })
logger.log({ str: 'hello world' }, 'basic log', 100, [1, 2, 3])
logger.info({ str: 'hello world' }, 'info log', 100, [1, 2, 3])
logger.debug({ str: 'hello world' }, 'debug log', 100, [1, 2, 3])
logger.warn({ str: 'hello world' }, 'warn log', 100, [1, 2, 3])
}
// Test case from `wx.getNetworkType`
{
wx.getNetworkType({
success(res) {
res.networkType
},
})
}
// Test case from `wx.getRealtimeLogManager`
{
// 小程序端
{
const logger = wx.getRealtimeLogManager()
logger.info({ str: 'hello world' }, 'info log', 100, [1, 2, 3])
logger.error({ str: 'hello world' }, 'error log', 100, [1, 2, 3])
logger.warn({ str: 'hello world' }, 'warn log', 100, [1, 2, 3])
}
// 插件端,基础库 2.16.0 版本后支持,只允许采用 key-value 的新格式上报
{
const logManager = wx.getRealtimeLogManager()
const logger = logManager.tag('plugin-log1')
logger.info('key1', 'value1')
logger.error('key2', { str: 'value2' })
logger.warn('key3', 'value3')
}
}
// Test case from `wx.getSelectedTextRange`
{
wx.getSelectedTextRange({
success(res) {
expectType<number>(res.start)
expectType<number>(res.end)
},
})
}
// Test case from `wx.getSetting`
{
wx.getSetting({
success(res) {
expectType<boolean | undefined>(res.authSetting['scope.address'])
expectType<boolean>(res.subscriptionsSetting.mainSwitch)
expectType<Record<string, any> | undefined>(res.subscriptionsSetting.itemSettings)
},
})
}
// Test case from `SubscriptionsSetting`
{
wx.getSetting({
withSubscriptions: true,
success(res) {
expectType<undefined | boolean>(res.authSetting['scope.userInfo'])
expectType<undefined | boolean>(res.authSetting['scope.userLocation'])
expectType<boolean>(res.subscriptionsSetting.mainSwitch)
if (res.subscriptionsSetting.itemSettings !== undefined) {
expectType<any>(res.subscriptionsSetting.itemSettings.SYS_MSG_TYPE_INTERACTIVE)
}
},
})
}
// Test case from `wx.getStorageInfoSync`
{
wx.getStorageInfo({
success(res) {
expectType<string[]>(res.keys)
expectType<number>(res.currentSize)
expectType<number>(res.limitSize)
},
})
}
// Test case from `wx.getStorageInfo`
{
wx.getStorageInfo({
success(res) {
expectType<string[]>(res.keys)
expectType<number>(res.currentSize)
expectType<number>(res.limitSize)
},
})
}
// Test case from `wx.getStorageSync`
{
wx.getStorage({
key: 'key',
success(res) {
expectType<any>(res.data)
},
})
}
// Test case from `wx.getStorage`
{
wx.getStorage({
key: 'key',
success(res) {
expectType<any>(res.data)
},
})
}
type TPlatform = 'ios' | 'android' | 'windows' | 'mac' | 'devtools' | 'ohos'
// Test case from `wx.getSystemInfoSync`
{