Skip to content

Commit 4e393db

Browse files
git-nandorbalzss
authored andcommitted
test(theme-registry): migrate old ThemeRegistry tests
1 parent f327d6b commit 4e393db

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/theme-registry/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
},
2929
"devDependencies": {
3030
"@instructure/ui-babel-preset": "10.20.1",
31-
"@instructure/ui-test-utils": "10.20.1"
31+
"@testing-library/jest-dom": "^6.6.3",
32+
"@testing-library/react": "^16.0.1",
33+
"vitest": "^3.2.2"
3234
}
3335
}

packages/theme-registry/src/__old-tests__/ThemeRegistry.test.ts renamed to packages/theme-registry/src/__tests__/ThemeRegistry.test.tsx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
import { vi, expect } from 'vitest'
25+
import type { MockInstance } from 'vitest'
2426
import type { BaseTheme } from '@instructure/shared-types'
25-
import { expect } from '@instructure/ui-test-utils'
2627
import { ThemeRegistry } from '../ThemeRegistry'
2728
const defaultRegistry = ThemeRegistry.getRegistry()
2829

@@ -40,17 +41,33 @@ const baseTheme = {
4041
}
4142

4243
describe('ThemeRegistry', () => {
44+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
45+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
46+
4347
beforeEach(() => {
4448
ThemeRegistry.clearRegistry()
49+
50+
// Mocking console to prevent test output pollution
51+
consoleWarningMock = vi
52+
.spyOn(console, 'warn')
53+
.mockImplementation(() => {}) as MockInstance
54+
consoleErrorMock = vi
55+
.spyOn(console, 'error')
56+
.mockImplementation(() => {}) as MockInstance
4557
})
58+
4659
afterEach(() => {
4760
ThemeRegistry.setRegistry(defaultRegistry)
61+
62+
consoleWarningMock.mockRestore()
63+
consoleErrorMock.mockRestore()
4864
})
65+
4966
it('should instantiate registry correctly', async () => {
5067
const registry = ThemeRegistry.getRegistry()
5168

52-
expect(registry).to.not.be.empty()
53-
expect(registry).to.eql({
69+
expect(registry).not.toEqual({})
70+
expect(registry).toEqual({
5471
currentThemeKey: null,
5572
themes: {},
5673
registered: []
@@ -69,9 +86,9 @@ describe('ThemeRegistry', () => {
6986
ThemeRegistry.registerTheme(theme as unknown as BaseTheme)
7087
const registry = ThemeRegistry.getRegistry()
7188

72-
expect(registry.registered).to.contain(theme.key)
73-
expect(registry.themes).to.have.key(theme.key)
74-
expect(registry.themes[theme.key]).to.not.be.empty()
89+
expect(registry.registered).toContain(theme.key)
90+
expect(Object.keys(registry.themes)).toContain(theme.key)
91+
expect(registry.themes[theme.key]).not.toEqual({})
7592
})
7693

7794
it('should be able to get the current theme', async () => {
@@ -90,8 +107,8 @@ describe('ThemeRegistry', () => {
90107

91108
const registry = ThemeRegistry.getRegistry()
92109

93-
expect(registry.currentThemeKey).to.be.eq(theme.key)
94-
expect(ThemeRegistry.getCurrentTheme()).to.be.eql(registeredTheme)
110+
expect(registry.currentThemeKey).toBe(theme.key)
111+
expect(ThemeRegistry.getCurrentTheme()).toEqual(registeredTheme)
95112
})
96113

97114
it('should be able to override themes with ".use()"', async () => {
@@ -115,7 +132,7 @@ describe('ThemeRegistry', () => {
115132
}
116133
}
117134
})
118-
expect(ThemeRegistry.getCurrentTheme()?.colors?.primitives?.white).to.be.eq(
135+
expect(ThemeRegistry.getCurrentTheme()?.colors?.primitives?.white).toBe(
119136
'blue'
120137
)
121138
})
@@ -130,6 +147,6 @@ describe('ThemeRegistry', () => {
130147
theme as unknown as BaseTheme
131148
)
132149
registeredTheme.use()
133-
}).to.throw(Error)
150+
}).toThrow(Error)
134151
})
135152
})

packages/theme-registry/tsconfig.build.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
{
1414
"path": "../ui-babel-preset/tsconfig.build.json"
1515
},
16-
{
17-
"path": "../ui-test-utils/tsconfig.build.json"
18-
},
1916
{
2017
"path": "../shared-types/tsconfig.build.json"
2118
},

0 commit comments

Comments
 (0)