Skip to content

Commit

Permalink
test for the platformstyle.js (#4168)
Browse files Browse the repository at this point in the history
* Create platformstyle.test.js

* Update jest.config.js

* Update musicutils.test.js

resolving conflicts with the platformstyle.test.js
  • Loading branch information
omsuneri authored Dec 24, 2024
1 parent 7be0371 commit 6d184bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
testMatch: ['**/__tests__/**/*.test.js', '**/?(*.)+(spec|test).[jt]s?(x)'],
clearMocks: true,
moduleFileExtensions: ['js', 'json', 'node'],
testEnvironment: 'jsdom',
};
2 changes: 2 additions & 0 deletions js/utils/__tests__/musicutils.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { TextEncoder } = require('util');
global.TextEncoder = TextEncoder;
global._ = jest.fn((str) => str);
global.window = {
btoa: jest.fn((str) => Buffer.from(str, "utf8").toString("base64"))
Expand Down
19 changes: 19 additions & 0 deletions js/utils/__tests__/platformstyle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe('Platform Style Tests', () => {
beforeEach(() => {
const meta = document.createElement('meta');
meta.name = 'theme-color';
document.head.appendChild(meta);
});

afterEach(() => {
document.head.innerHTML = '';
});

test('should set the meta theme-color content based on platformColor', () => {
const platformColor = { header: '#ff0000' };
document.querySelector("meta[name=theme-color]").content = platformColor.header;

const meta = document.querySelector("meta[name=theme-color]");
expect(meta.content).toBe('#ff0000');
});
});

0 comments on commit 6d184bb

Please sign in to comment.