summaryrefslogtreecommitdiff
path: root/packages/webapi/test/base64.js
blob: 69564180559af783d7f489e7c67a441c534f3a7a (plain) (blame)
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
import { assert, test } from '../run/test.setup.js'
import { polyfill } from '../mod.js'

test(() => {
	return [
		{
			name: 'Supports Base64 Methods',
			test() {
				const target = {}

				polyfill(target)

				assert.equal('atob' in target, true)
				assert.equal('btoa' in target, true)
				assert.equal(typeof target['atob'], 'function')
				assert.equal(typeof target['btoa'], 'function')
			},
		},
		{
			name: 'Supports atob(data)',
			test() {
				const target = {}

				polyfill(target)

				const a = 'SGVsbG8sIHdvcmxk'
				const b = target.atob(a)

				assert.equal(a, 'SGVsbG8sIHdvcmxk')
				assert.equal(b, 'Hello, world')
			},
		},
		{
			name: 'Supports btoa(data)',
			test() {
				const target = {}

				polyfill(target)

				const b = 'Hello, world'
				const a = target.btoa(b)

				assert.equal(a, 'SGVsbG8sIHdvcmxk')
				assert.equal(b, 'Hello, world')
			},
		},
	]
})