@exodus/networking-spec
Version:
Platform-agnostic test suites for networking related features
93 lines (92 loc) • 4.1 kB
JavaScript
export function testsuite(getInstance) {
describe('FormData', () => {
let formData;
beforeEach(() => {
formData = getInstance();
});
it('should set a value', () => {
const city = 'Gotham City';
formData.set('city', city);
expect(formData.get('city')).toEqual(city);
});
it('should append values', () => {
const locations = ['Wayne Manor', 'Wayne Tower'];
locations.forEach((location) => {
formData.append('location', location);
});
expect(formData.getAll('location')).toEqual(locations);
});
describe('with entries', () => {
beforeEach(() => {
formData.set('city', 'Gotham City');
formData.set('name', 'Bruce Wayne');
formData.append('name', 'Batman');
});
it('should override a value', () => {
formData.set('city', 'Woolloomooloo');
expect(formData.get('city')).toEqual('Woolloomooloo');
});
it('should delete a value', () => {
formData.delete('city');
expect(formData.has('city')).toEqual(false);
expect(formData.get('city')).toEqual(null);
});
it('should return entries when iterating over itself', () => {
expect([...formData]).toEqual([
['city', 'Gotham City'],
['name', 'Bruce Wayne'],
['name', 'Batman'],
]);
});
it('should return existing entries', () => {
expect([...formData.entries()]).toEqual([
['city', 'Gotham City'],
['name', 'Bruce Wayne'],
['name', 'Batman'],
]);
});
it('should return existing values', () => {
expect([...formData.values()]).toEqual(['Gotham City', 'Bruce Wayne', 'Batman']);
});
it('should return existing keys', () => {
expect([...formData.keys()]).toEqual(['city', 'name', 'name']);
});
it('should return true when testing key for presence ', () => {
expect(formData.has('city')).toEqual(true);
expect(formData.has('name')).toEqual(true);
});
it('should return value for key', () => {
expect(formData.get('city')).toEqual('Gotham City');
expect(formData.get('name')).toEqual('Bruce Wayne');
});
it('should return all values for key', () => {
expect(formData.getAll('name')).toEqual(['Bruce Wayne', 'Batman']);
});
});
describe('empty', () => {
it('should return nothing when iterating over itself', () => {
for (const entry of formData) {
fail(`Should be empty but has value: ${entry.toString()}`);
}
});
it('should return a completed iterator from entries()', () => {
const iterator = formData.entries();
expect(iterator.next()).toEqual({ done: true, value: undefined });
});
it('should return a completed iterator from values()', () => {
const iterator = formData.values();
expect(iterator.next()).toEqual({ done: true, value: undefined });
});
it('should return a completed iterator from keys()', () => {
const iterator = formData.keys();
expect(iterator.next()).toEqual({ done: true, value: undefined });
});
it('should return false when testing any key for presence ', () => {
expect(formData.has('wayne-foundation')).toEqual(false);
});
it('should return null when getting any key', () => {
expect(formData.get('wayne-foundation')).toBeNull();
});
});
});
}