Compare commits

...

3 Commits

Author SHA1 Message Date
Julien Déramond a40f442f7b Merge branch 'main' into gs/data-must-set-onlu-one-instance 2022-11-11 09:50:59 +01:00
George Sotiropoulos b5bed16fdf test: add test for shown message 2022-11-09 10:24:51 +02:00
George Sotiropoulos 2d56711f48 fix: Data.js must not overwrite exising element instance 2022-11-09 10:24:51 +02:00
2 changed files with 14 additions and 14 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ export default {
// make it clear we only want one instance per element
// can be removed later when multiple key/instances are fine to be used
if (!instanceMap.has(key) && instanceMap.size !== 0) {
if (instanceMap.size !== 0) {
// eslint-disable-next-line no-console
console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`)
return
+13 -13
View File
@@ -53,18 +53,6 @@ describe('Data', () => {
expect(Data.get(div, TEST_KEY)).toEqual(data)
})
it('should overwrite data if something is already stored', () => {
const data = { ...TEST_DATA }
const copy = { ...data }
Data.set(div, TEST_KEY, data)
Data.set(div, TEST_KEY, copy)
// Using `toBe` since spread creates a shallow copy
expect(Data.get(div, TEST_KEY)).not.toBe(data)
expect(Data.get(div, TEST_KEY)).toBe(copy)
})
it('should do nothing when an element has nothing stored', () => {
Data.remove(div, TEST_KEY)
@@ -99,8 +87,20 @@ describe('Data', () => {
Data.set(div, TEST_KEY, data)
Data.set(div, UNKNOWN_KEY, copy)
expect(console.error).toHaveBeenCalled()
expect(console.error).toHaveBeenCalledWith(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${TEST_KEY}.`)
expect(Data.get(div, UNKNOWN_KEY)).toBeNull()
})
it('should console.error a message if "set" is for the same element', () => {
console.error = jasmine.createSpy('console.error')
const data = { ...TEST_DATA }
Data.set(div, TEST_KEY, data)
Data.set(div, TEST_KEY, data)
expect(console.error).toHaveBeenCalledWith(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${TEST_KEY}.`)
expect(Data.get(div, TEST_KEY)).toEqual(data)
})
/* eslint-enable no-console */
})