Skip to content

Commit

Permalink
chore: webapi test now use chai (withastro#3048)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanM04 authored Apr 11, 2022
1 parent 47f20a1 commit 1907255
Show file tree
Hide file tree
Showing 16 changed files with 539 additions and 814 deletions.
2 changes: 2 additions & 0 deletions packages/webapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
"@rollup/plugin-inject": "^4.0.4",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-typescript": "^8.3.1",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.1.0",
"@types/node": "^14.18.12",
"@ungap/structured-clone": "^0.3.4",
"abort-controller": "^3.0.0",
"chai": "^4.3.6",
"event-target-shim": "^6.0.2",
"fetch-blob": "^3.1.5",
"formdata-polyfill": "^4.0.10",
Expand Down
29 changes: 0 additions & 29 deletions packages/webapi/run/test.setup.js

This file was deleted.

59 changes: 20 additions & 39 deletions packages/webapi/test/base64.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,29 @@
import { assert, test } from '../run/test.setup.js'
import { expect } from 'chai'
import { polyfill } from '../mod.js'

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

polyfill(target)
before(() => 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 = {}
it('Supports Base64 Methods', () => {
expect(target).to.have.property('atob').that.is.a('function')
expect(target).to.have.property('btoa').that.is.a('function')
})

polyfill(target)
it('Supports atob(data)', () => {
const a = 'SGVsbG8sIHdvcmxk'
const b = target.atob(a)

const a = 'SGVsbG8sIHdvcmxk'
const b = target.atob(a)
expect(a).to.equal('SGVsbG8sIHdvcmxk')
expect(b).to.equal('Hello, world')
})

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

polyfill(target)

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

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

0 comments on commit 1907255

Please sign in to comment.