-
- `
- document.body.append(el)
- for (const host of document.querySelectorAll('.shadow-host-with-slot')) {
- const shadowRoot = host.attachShadow({mode: 'open'})
- const slot = document.createElement('slot')
- slot.name = 'slot'
- shadowRoot.appendChild(slot)
- }
- expect(checkVisibility.call(document.getElementById('visibilityhidden'), {checkVisibilityCSS: true})).to.equal(
- false,
- )
- expect(checkVisibility.call(document.getElementById('visibilityhidden'), {checkVisibilityCSS: false})).to.equal(
- true,
- )
- expect(checkVisibility.call(document.getElementById('cvhidden'))).to.equal(false)
- expect(checkVisibility.call(document.getElementById('slottedincvhidden'))).to.equal(false)
- expect(checkVisibility.call(document.getElementById('cvauto'))).to.equal(true)
- expect(checkVisibility.call(document.getElementById('cvautooffscreen'))).to.equal(true)
- expect(checkVisibility.call(document.getElementById('displaynone'))).to.equal(false)
- expect(checkVisibility.call(document.getElementById('slottedindisplaynone'))).to.equal(false)
- expect(checkVisibility.call(document.getElementById('displaycontents'))).to.equal(false)
- expect(checkVisibility.call(document.getElementById('displaycontentschild'))).to.equal(true)
- expect(checkVisibility.call(document.getElementById('opacityzero'), {checkOpacity: true})).to.equal(false)
- expect(checkVisibility.call(document.getElementById('opacityzero'), {checkOpacity: false})).to.equal(true)
- expect(checkVisibility.call(document.getElementById('slottedinopacityzero'), {checkOpacity: true})).to.equal(false)
- expect(checkVisibility.call(document.getElementById('slottedinopacityzero'), {checkOpacity: false})).to.equal(true)
- const cvautocontainer = document.getElementById('cvautocontainer')
- const cvautochild = document.getElementById('cvautochild')
- cvautocontainer.style.contentVisibility = 'auto'
- cvautochild.style.visibility = 'hidden'
- expect(checkVisibility.call(cvautochild, {checkVisibilityCSS: true})).to.equal(false)
- cvautochild.style.visibility = 'visible'
- expect(checkVisibility.call(cvautochild, {checkVisibilityCSS: true})).to.equal(true)
- expect(checkVisibility.call(document.getElementById('nestedcvautochild'))).to.equal(true)
- const cvhiddenchildwithupdate = document.getElementById('cvhiddenchildwithupdate')
- cvhiddenchildwithupdate.getBoundingClientRect()
- expect(checkVisibility.call(cvhiddenchildwithupdate)).to.equal(false)
- const cvhiddenwithupdate = document.getElementById('cvhiddenwithupdate')
- cvhiddenwithupdate.getBoundingClientRect()
- expect(checkVisibility.call(cvhiddenwithupdate)).to.equal(true)
- })
-})
diff --git a/test/iterator-helpers.js b/test/iterator-helpers.js
deleted file mode 100644
index 1c717e8..0000000
--- a/test/iterator-helpers.js
+++ /dev/null
@@ -1,303 +0,0 @@
-import {expect} from 'chai'
-import {apply, isPolyfilled, isSupported} from '../src/iterator-helpers.ts'
-
-// eslint-disable-next-line i18n-text/no-en
-describe('Iterator helpers', () => {
- it('has standard isSupported, isPolyfilled, apply API', () => {
- expect(isSupported).to.be.a('function')
- expect(isPolyfilled).to.be.a('function')
- expect(apply).to.be.a('function')
- expect(isSupported()).to.be.a('boolean')
- expect(isPolyfilled()).to.equal(false)
- })
-
- it('isSupported returns true when Iterator is a function (native support)', () => {
- // Native Iterator in Chromium is a function, not an object.
- // Simulate this by temporarily replacing globalThis.Iterator with a function.
- const original = globalThis.Iterator
- try {
- apply() // ensure polyfill is applied first so prototype methods exist
- const proto = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()))
- // Create a function-based Iterator with a `from` method, like native Chromium
- globalThis.Iterator = function Iterator() {}
- globalThis.Iterator.from = function from() {}
- // Assign all required methods to the iterator prototype
- for (const method of [
- 'map',
- 'filter',
- 'take',
- 'drop',
- 'flatMap',
- 'reduce',
- 'toArray',
- 'forEach',
- 'some',
- 'every',
- 'find',
- ]) {
- if (!(method in proto)) {
- proto[method] = function () {}
- }
- }
- expect(isSupported()).to.equal(true)
- } finally {
- globalThis.Iterator = original
- }
- })
-
- // Helper to create an iterator from an array
- function* arrayIterator(arr) {
- for (const item of arr) {
- yield item
- }
- }
-
- describe('map', () => {
- beforeEach(() => apply())
-
- it('maps values', () => {
- const iter = arrayIterator([1, 2, 3])
- const mapped = iter.map(x => x * 2)
- expect([...mapped]).to.eql([2, 4, 6])
- })
-
- it('passes index to mapper', () => {
- const iter = arrayIterator(['a', 'b', 'c'])
- const mapped = iter.map((x, i) => `${i}:${x}`)
- expect([...mapped]).to.eql(['0:a', '1:b', '2:c'])
- })
- })
-
- describe('filter', () => {
- beforeEach(() => apply())
-
- it('filters values', () => {
- const iter = arrayIterator([1, 2, 3, 4, 5])
- const filtered = iter.filter(x => x % 2 === 0)
- expect([...filtered]).to.eql([2, 4])
- })
-
- it('passes index to predicate', () => {
- const iter = arrayIterator(['a', 'b', 'c', 'd'])
- const filtered = iter.filter((_, i) => i % 2 === 0)
- expect([...filtered]).to.eql(['a', 'c'])
- })
- })
-
- describe('take', () => {
- beforeEach(() => apply())
-
- it('takes first n values', () => {
- const iter = arrayIterator([1, 2, 3, 4, 5])
- const taken = iter.take(3)
- expect([...taken]).to.eql([1, 2, 3])
- })
-
- it('handles taking more than available', () => {
- const iter = arrayIterator([1, 2])
- const taken = iter.take(5)
- expect([...taken]).to.eql([1, 2])
- })
- })
-
- describe('drop', () => {
- beforeEach(() => apply())
-
- it('drops first n values', () => {
- const iter = arrayIterator([1, 2, 3, 4, 5])
- const dropped = iter.drop(2)
- expect([...dropped]).to.eql([3, 4, 5])
- })
-
- it('handles dropping more than available', () => {
- const iter = arrayIterator([1, 2])
- const dropped = iter.drop(5)
- expect([...dropped]).to.eql([])
- })
- })
-
- describe('flatMap', () => {
- beforeEach(() => apply())
-
- it('flattens mapped values', () => {
- const iter = arrayIterator([1, 2, 3])
- const flatMapped = iter.flatMap(x => [x, x * 2])
- expect([...flatMapped]).to.eql([1, 2, 2, 4, 3, 6])
- })
-
- it('handles empty results', () => {
- const iter = arrayIterator([1, 2, 3])
- const flatMapped = iter.flatMap(x => (x % 2 === 0 ? [x] : []))
- expect([...flatMapped]).to.eql([2])
- })
- })
-
- describe('reduce', () => {
- beforeEach(() => apply())
-
- it('reduces with initial value', () => {
- const iter = arrayIterator([1, 2, 3, 4])
- const sum = iter.reduce((acc, x) => acc + x, 0)
- expect(sum).to.equal(10)
- })
-
- it('reduces without initial value uses first element as accumulator', () => {
- const iter = arrayIterator([1, 2, 3, 4])
- const calls = []
- iter.reduce((acc, x, i) => {
- calls.push({acc, x, index: i})
- return acc + x
- })
- // First element (1) is used as accumulator; reducer is called starting at index 1
- expect(calls).to.eql([
- {acc: 1, x: 2, index: 1},
- {acc: 3, x: 3, index: 2},
- {acc: 6, x: 4, index: 3},
- ])
- })
-
- it('reduces without initial value returns correct sum', () => {
- const iter = arrayIterator([1, 2, 3, 4])
- const sum = iter.reduce((acc, x) => acc + x)
- expect(sum).to.equal(10)
- })
-
- it('throws on empty iterator without initial value', () => {
- const iter = arrayIterator([])
- expect(() => iter.reduce((acc, x) => acc + x)).to.throw(TypeError)
- })
-
- it('treats explicit undefined as a provided initial value', () => {
- const iter = arrayIterator([1, 2, 3])
- const calls = []
- iter.reduce((acc, x, i) => {
- calls.push({acc, x, index: i})
- return x
- }, undefined)
- // undefined is the initial accumulator; reducer is called starting at index 0
- expect(calls[0]).to.eql({acc: undefined, x: 1, index: 0})
- expect(calls).to.have.lengthOf(3)
- })
- })
-
- describe('toArray', () => {
- beforeEach(() => apply())
-
- it('converts iterator to array', () => {
- const iter = arrayIterator([1, 2, 3])
- expect(iter.toArray()).to.eql([1, 2, 3])
- })
-
- it('handles empty iterator', () => {
- const iter = arrayIterator([])
- expect(iter.toArray()).to.eql([])
- })
- })
-
- describe('forEach', () => {
- beforeEach(() => apply())
-
- it('calls callback for each value', () => {
- const iter = arrayIterator([1, 2, 3])
- const results = []
- // eslint-disable-next-line github/array-foreach
- iter.forEach((x, i) => results.push({value: x, index: i}))
- expect(results).to.eql([
- {value: 1, index: 0},
- {value: 2, index: 1},
- {value: 3, index: 2},
- ])
- })
- })
-
- describe('some', () => {
- beforeEach(() => apply())
-
- it('returns true if any value matches', () => {
- const iter = arrayIterator([1, 2, 3, 4])
- expect(iter.some(x => x > 3)).to.be.true
- })
-
- it('returns false if no value matches', () => {
- const iter = arrayIterator([1, 2, 3])
- expect(iter.some(x => x > 5)).to.be.false
- })
- })
-
- describe('every', () => {
- beforeEach(() => apply())
-
- it('returns true if all values match', () => {
- const iter = arrayIterator([2, 4, 6])
- expect(iter.every(x => x % 2 === 0)).to.be.true
- })
-
- it('returns false if any value does not match', () => {
- const iter = arrayIterator([2, 3, 4])
- expect(iter.every(x => x % 2 === 0)).to.be.false
- })
- })
-
- describe('find', () => {
- beforeEach(() => apply())
-
- it('returns first matching value', () => {
- const iter = arrayIterator([1, 2, 3, 4])
- expect(iter.find(x => x > 2)).to.equal(3)
- })
-
- it('returns undefined if no match', () => {
- const iter = arrayIterator([1, 2, 3])
- expect(iter.find(x => x > 5)).to.be.undefined
- })
- })
-
- describe('Iterator.from', () => {
- beforeEach(() => apply())
-
- it('converts iterable to iterator', () => {
- const IteratorConstructor = globalThis.Iterator
- if (!IteratorConstructor?.from) {
- // Skip if Iterator.from is not available after polyfill
- return
- }
- const iter = IteratorConstructor.from([1, 2, 3])
- expect([...iter]).to.eql([1, 2, 3])
- })
-
- it('returns iterator as-is', () => {
- const IteratorConstructor = globalThis.Iterator
- if (!IteratorConstructor?.from) {
- // Skip if Iterator.from is not available after polyfill
- return
- }
- const original = arrayIterator([1, 2, 3])
- const iter = IteratorConstructor.from(original)
- expect(iter).to.equal(original)
- })
-
- it('handles primitive iterable strings', () => {
- const IteratorConstructor = globalThis.Iterator
- if (!IteratorConstructor?.from) {
- // Skip if Iterator.from is not available after polyfill
- return
- }
- const iter = IteratorConstructor.from('abc')
- expect([...iter]).to.eql(['a', 'b', 'c'])
- })
- })
-
- describe('chaining', () => {
- beforeEach(() => apply())
-
- it('chains multiple operations', () => {
- const iter = arrayIterator([1, 2, 3, 4, 5, 6])
- const result = iter
- .filter(x => x % 2 === 0)
- .map(x => x * 2)
- .take(2)
- .toArray()
- expect(result).to.eql([4, 8])
- })
- })
-})
diff --git a/test/map-groupby.js b/test/map-groupby.js
deleted file mode 100644
index e632ccb..0000000
--- a/test/map-groupby.js
+++ /dev/null
@@ -1,58 +0,0 @@
-import {expect} from 'chai'
-import {apply, isPolyfilled, isSupported, groupBy} from '../src/map-groupby.ts'
-
-describe('Map.groupBy', () => {
- it('has standard isSupported, isPolyfilled, apply API', () => {
- expect(isSupported).to.be.a('function')
- expect(isPolyfilled).to.be.a('function')
- expect(apply).to.be.a('function')
- expect(isSupported()).to.be.a('boolean')
- expect(isPolyfilled()).to.equal(false)
- })
-
- it('groups items by key', () => {
- const items = [
- {type: 'fruit', name: 'apple'},
- {type: 'vegetable', name: 'carrot'},
- {type: 'fruit', name: 'banana'},
- {type: 'vegetable', name: 'broccoli'},
- ]
- const result = groupBy(items, item => item.type)
- expect(result).to.be.instanceOf(Map)
- expect(result.has('fruit')).to.be.true
- expect(result.get('fruit')).to.have.lengthOf(2)
- expect(result.get('fruit')?.[0]).to.eql({type: 'fruit', name: 'apple'})
- expect(result.get('fruit')?.[1]).to.eql({type: 'fruit', name: 'banana'})
- expect(result.has('vegetable')).to.be.true
- expect(result.get('vegetable')).to.have.lengthOf(2)
- expect(result.get('vegetable')?.[0]).to.eql({type: 'vegetable', name: 'carrot'})
- expect(result.get('vegetable')?.[1]).to.eql({type: 'vegetable', name: 'broccoli'})
- })
-
- it('passes index to callback', () => {
- const items = ['a', 'b', 'c', 'd']
- const result = groupBy(items, (_item, index) => (index % 2 === 0 ? 'even' : 'odd'))
- expect(result.get('even')).to.eql(['a', 'c'])
- expect(result.get('odd')).to.eql(['b', 'd'])
- })
-
- it('handles empty arrays', () => {
- const result = groupBy([], () => 'key')
- expect(result.size).to.equal(0)
- })
-
- it('works with object keys', () => {
- const keyA = {id: 1}
- const keyB = {id: 2}
- const items = [
- {key: keyA, value: 'a'},
- {key: keyB, value: 'b'},
- {key: keyA, value: 'c'},
- ]
- const result = groupBy(items, item => item.key)
- expect(result.has(keyA)).to.be.true
- expect(result.get(keyA)).to.have.lengthOf(2)
- expect(result.has(keyB)).to.be.true
- expect(result.get(keyB)).to.have.lengthOf(1)
- })
-})
diff --git a/test/navigator-clipboard.js b/test/navigator-clipboard.js
deleted file mode 100644
index c13d6c0..0000000
--- a/test/navigator-clipboard.js
+++ /dev/null
@@ -1,55 +0,0 @@
-import {expect} from 'chai'
-import {clipboardRead, clipboardWrite, apply, isPolyfilled, isSupported} from '../src/navigator-clipboard.ts'
-
-describe('navigator clipboard', () => {
- it('has standard isSupported, isPolyfilled, apply API', () => {
- expect(isSupported).to.be.a('function')
- expect(isPolyfilled).to.be.a('function')
- expect(apply).to.be.a('function')
- expect(isSupported()).to.be.a('boolean')
- expect(isPolyfilled()).to.equal(false)
- })
-
- describe('read', () => {
- it('read returns array of 1 clipboard entry with plaintext of readText value', async () => {
- navigator.clipboard.readText = () => Promise.resolve('foo')
- const arr = await clipboardRead()
- expect(arr).to.have.lengthOf(1)
- expect(arr[0]).to.be.an.instanceof(globalThis.ClipboardItem)
- expect(arr[0].types).to.eql(['text/plain'])
- expect(await (await arr[0].getType('text/plain')).text()).to.eql('foo')
- })
- })
-
- describe('write', () => {
- it('unpacks text/plain content to writeText', async () => {
- const calls = []
- navigator.clipboard.writeText = (...args) => calls.push(args)
- await clipboardWrite([
- new globalThis.ClipboardItem({
- 'foo/bar': 'horrible',
- 'text/plain': Promise.resolve('foo'),
- }),
- ])
- expect(calls).to.have.lengthOf(1)
- expect(calls[0]).to.eql(['foo'])
- })
-
- it('accepts multiple clipboard items, picking the first', async () => {
- const calls = []
- navigator.clipboard.writeText = (...args) => calls.push(args)
- await clipboardWrite([
- new globalThis.ClipboardItem({
- 'foo/bar': 'horrible',
- 'text/plain': Promise.resolve('multiple-pass'),
- }),
- new globalThis.ClipboardItem({
- 'foo/bar': 'multiple-fail',
- 'text/plain': Promise.resolve('multiple-fail'),
- }),
- ])
- expect(calls).to.have.lengthOf(1)
- expect(calls[0]).to.eql(['multiple-pass'])
- })
- })
-})
diff --git a/test/object-groupby.js b/test/object-groupby.js
deleted file mode 100644
index 6d469e3..0000000
--- a/test/object-groupby.js
+++ /dev/null
@@ -1,61 +0,0 @@
-import {expect} from 'chai'
-import {apply, isPolyfilled, isSupported, groupBy} from '../src/object-groupby.ts'
-
-describe('Object.groupBy', () => {
- it('has standard isSupported, isPolyfilled, apply API', () => {
- expect(isSupported).to.be.a('function')
- expect(isPolyfilled).to.be.a('function')
- expect(apply).to.be.a('function')
- expect(isSupported()).to.be.a('boolean')
- expect(isPolyfilled()).to.equal(false)
- })
-
- it('groups items by key', () => {
- const items = [
- {type: 'fruit', name: 'apple'},
- {type: 'vegetable', name: 'carrot'},
- {type: 'fruit', name: 'banana'},
- {type: 'vegetable', name: 'broccoli'},
- ]
- const result = groupBy(items, item => item.type)
- expect(result).to.have.property('fruit')
- expect(result.fruit).to.have.lengthOf(2)
- expect(result.fruit?.[0]).to.eql({type: 'fruit', name: 'apple'})
- expect(result.fruit?.[1]).to.eql({type: 'fruit', name: 'banana'})
- expect(result).to.have.property('vegetable')
- expect(result.vegetable).to.have.lengthOf(2)
- expect(result.vegetable?.[0]).to.eql({type: 'vegetable', name: 'carrot'})
- expect(result.vegetable?.[1]).to.eql({type: 'vegetable', name: 'broccoli'})
- })
-
- it('passes index to callback', () => {
- const items = ['a', 'b', 'c', 'd']
- const result = groupBy(items, (_item, index) => (index % 2 === 0 ? 'even' : 'odd'))
- expect(result.even).to.eql(['a', 'c'])
- expect(result.odd).to.eql(['b', 'd'])
- })
-
- it('handles empty arrays', () => {
- const result = groupBy([], () => 'key')
- expect(Object.keys(result)).to.have.lengthOf(0)
- })
-
- it('works with numeric keys', () => {
- const items = [1, 2, 3, 4, 5, 6]
- const result = groupBy(items, item => item % 3)
- expect(result[0]).to.eql([3, 6])
- expect(result[1]).to.eql([1, 4])
- expect(result[2]).to.eql([2, 5])
- })
-
- it('handles __proto__ key safely without prototype pollution', () => {
- const items = ['a', 'b', 'c']
- const result = groupBy(items, (_item, index) => (index === 0 ? '__proto__' : 'other'))
- // The __proto__ key should exist as an own property, not affect Object.prototype
- expect(Object.prototype.hasOwnProperty.call(result, '__proto__')).to.be.true
- expect(result['__proto__']).to.eql(['a'])
- expect(result['other']).to.eql(['b', 'c'])
- // Object.prototype should not be polluted
- expect({}['__proto__']).to.not.eql(['a'])
- })
-})
diff --git a/test/promise-try.js b/test/promise-try.js
deleted file mode 100644
index 244e0b7..0000000
--- a/test/promise-try.js
+++ /dev/null
@@ -1,49 +0,0 @@
-import {expect} from 'chai'
-import {apply, isPolyfilled, isSupported, promiseTry} from '../src/promise-try.ts'
-
-describe('Promise.try', () => {
- it('has standard isSupported, isPolyfilled, apply API', () => {
- expect(isSupported).to.be.a('function')
- expect(isPolyfilled).to.be.a('function')
- expect(apply).to.be.a('function')
- expect(isSupported()).to.be.a('boolean')
- expect(isPolyfilled()).to.equal(false)
- })
-
- it('resolves with the return value of a successful function', async () => {
- const result = await promiseTry(() => 42)
- expect(result).to.equal(42)
- })
-
- it('resolves with the resolved value of a returned promise', async () => {
- const result = await promiseTry(() => Promise.resolve(42))
- expect(result).to.equal(42)
- })
-
- it('rejects with the error thrown by the function', async () => {
- const error = new Error('rejected')
- try {
- await promiseTry(() => {
- throw error
- })
- expect.fail('should fail')
- } catch (e) {
- expect(e).to.equal(error)
- }
- })
-
- it('rejects with the rejected value of a returned promise', async () => {
- const error = new Error('rejected')
- try {
- await promiseTry(() => Promise.reject(error))
- expect.fail('should fail')
- } catch (e) {
- expect(e).to.equal(error)
- }
- })
-
- it('handles synchronous values', async () => {
- const result = await promiseTry(() => 'sync')
- expect(result).to.equal('sync')
- })
-})
diff --git a/test/promise-withResolvers.js b/test/promise-withResolvers.js
deleted file mode 100644
index 3038634..0000000
--- a/test/promise-withResolvers.js
+++ /dev/null
@@ -1,41 +0,0 @@
-import {expect} from 'chai'
-import {apply, isPolyfilled, isSupported, withResolvers} from '../src/promise-withResolvers.ts'
-
-describe('withResolvers', () => {
- it('has standard isSupported, isPolyfilled, apply API', () => {
- expect(isSupported).to.be.a('function')
- expect(isPolyfilled).to.be.a('function')
- expect(apply).to.be.a('function')
- expect(isSupported()).to.be.a('boolean')
- expect(isPolyfilled()).to.equal(false)
- })
-
- it('resolves to first resolving value', async () => {
- const arg = withResolvers()
- expect(Object.keys(arg).sort()).to.eql(['promise', 'reject', 'resolve'])
- expect(arg).to.have.property('promise').to.be.a('promise')
- expect(arg).to.have.property('resolve').to.be.a('function')
- expect(arg).to.have.property('reject').to.be.a('function')
-
- arg.resolve(1)
- expect(await arg.promise).to.be.eql(1)
- })
-
- it('rejects to first rejecting reason', async () => {
- const arg = withResolvers()
- expect(Object.keys(arg).sort()).to.eql(['promise', 'reject', 'resolve'])
- expect(arg).to.have.property('promise').to.be.a('promise')
- expect(arg).to.have.property('resolve').to.be.a('function')
- expect(arg).to.have.property('reject').to.be.a('function')
-
- const err = new Error('rejected')
-
- try {
- arg.reject(err)
- await arg.promise
- expect.fail('should fail')
- } catch (e) {
- expect(e).to.be.eql(err)
- }
- })
-})
diff --git a/test/set-methods.js b/test/set-methods.js
deleted file mode 100644
index bfecbb8..0000000
--- a/test/set-methods.js
+++ /dev/null
@@ -1,148 +0,0 @@
-import {expect} from 'chai'
-import {
- apply,
- isPolyfilled,
- isSupported,
- union,
- intersection,
- difference,
- symmetricDifference,
- isSubsetOf,
- isSupersetOf,
- isDisjointFrom,
-} from '../src/set-methods.ts'
-
-// eslint-disable-next-line i18n-text/no-en
-describe('Set methods', () => {
- it('has standard isSupported, isPolyfilled, apply API', () => {
- expect(isSupported).to.be.a('function')
- expect(isPolyfilled).to.be.a('function')
- expect(apply).to.be.a('function')
- expect(isSupported()).to.be.a('boolean')
- expect(isPolyfilled()).to.equal(false)
- })
-
- describe('union', () => {
- it('returns a new Set with elements from both sets', () => {
- const a = new Set([1, 2, 3])
- const b = new Set([3, 4, 5])
- const result = union.call(a, b)
- expect(result).to.be.instanceof(Set)
- expect([...result].sort()).to.eql([1, 2, 3, 4, 5])
- })
-
- it('handles empty sets', () => {
- const a = new Set([1, 2])
- const result = union.call(a, new Set())
- expect([...result].sort()).to.eql([1, 2])
- })
- })
-
- describe('intersection', () => {
- it('returns a new Set with elements in both sets', () => {
- const a = new Set([1, 2, 3])
- const b = new Set([2, 3, 4])
- const result = intersection.call(a, b)
- expect(result).to.be.instanceof(Set)
- expect([...result].sort()).to.eql([2, 3])
- })
-
- it('returns empty set when no common elements', () => {
- const a = new Set([1, 2])
- const b = new Set([3, 4])
- const result = intersection.call(a, b)
- expect(result.size).to.equal(0)
- })
- })
-
- describe('difference', () => {
- it('returns a new Set with elements in this but not other', () => {
- const a = new Set([1, 2, 3])
- const b = new Set([2, 3, 4])
- const result = difference.call(a, b)
- expect(result).to.be.instanceof(Set)
- expect([...result]).to.eql([1])
- })
-
- it('returns a copy of this when no overlap', () => {
- const a = new Set([1, 2])
- const b = new Set([3, 4])
- const result = difference.call(a, b)
- expect([...result].sort()).to.eql([1, 2])
- })
- })
-
- describe('symmetricDifference', () => {
- it('returns elements in one set but not both', () => {
- const a = new Set([1, 2, 3])
- const b = new Set([2, 3, 4])
- const result = symmetricDifference.call(a, b)
- expect(result).to.be.instanceof(Set)
- expect([...result].sort()).to.eql([1, 4])
- })
-
- it('returns empty set for identical sets', () => {
- const a = new Set([1, 2])
- const result = symmetricDifference.call(a, new Set([1, 2]))
- expect(result.size).to.equal(0)
- })
- })
-
- describe('isSubsetOf', () => {
- it('returns true when all elements are in the other set', () => {
- const a = new Set([1, 2])
- const b = new Set([1, 2, 3])
- expect(isSubsetOf.call(a, b)).to.equal(true)
- })
-
- it('returns false when some elements are not in the other set', () => {
- const a = new Set([1, 2, 4])
- const b = new Set([1, 2, 3])
- expect(isSubsetOf.call(a, b)).to.equal(false)
- })
-
- it('returns true for empty set', () => {
- const a = new Set()
- const b = new Set([1, 2])
- expect(isSubsetOf.call(a, b)).to.equal(true)
- })
- })
-
- describe('isSupersetOf', () => {
- it('returns true when this set contains all elements of other', () => {
- const a = new Set([1, 2, 3])
- const b = new Set([1, 2])
- expect(isSupersetOf.call(a, b)).to.equal(true)
- })
-
- it('returns false when other has elements not in this', () => {
- const a = new Set([1, 2])
- const b = new Set([1, 2, 3])
- expect(isSupersetOf.call(a, b)).to.equal(false)
- })
-
- it('returns true when other is empty', () => {
- const a = new Set([1, 2])
- expect(isSupersetOf.call(a, new Set())).to.equal(true)
- })
- })
-
- describe('isDisjointFrom', () => {
- it('returns true when sets have no common elements', () => {
- const a = new Set([1, 2])
- const b = new Set([3, 4])
- expect(isDisjointFrom.call(a, b)).to.equal(true)
- })
-
- it('returns false when sets share elements', () => {
- const a = new Set([1, 2, 3])
- const b = new Set([3, 4])
- expect(isDisjointFrom.call(a, b)).to.equal(false)
- })
-
- it('returns true when either set is empty', () => {
- const a = new Set([1, 2])
- expect(isDisjointFrom.call(a, new Set())).to.equal(true)
- })
- })
-})