Skip to content

Commit

Permalink
fix: [#1611] Implement window.TextEncoder & window.TextDecoder
Browse files Browse the repository at this point in the history
Co-authored-by: David Ortner <david@ortner.se>
  • Loading branch information
Ayc0 and capricorn86 authored Nov 14, 2024
1 parent 78d8914 commit 7914b54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/happy-dom/src/window/BrowserWindow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Buffer } from 'buffer';
import { webcrypto } from 'crypto';
import { TextEncoder, TextDecoder } from 'util';
import Stream from 'stream';
import { ReadableStream } from 'stream/web';
import { URLSearchParams } from 'url';
Expand Down Expand Up @@ -707,6 +708,8 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
public readonly screenX: number = 0;
public readonly screenY: number = 0;
public readonly crypto: typeof webcrypto = webcrypto;
public readonly TextEncoder: typeof TextEncoder = TextEncoder;
public readonly TextDecoder: typeof TextDecoder = TextDecoder;
public readonly closed = false;
public console: Console;
public name = '';
Expand Down
18 changes: 15 additions & 3 deletions packages/happy-dom/test/window/BrowserWindow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ describe('BrowserWindow', () => {
});
});

describe('get TextEncoder()', () => {
it('Returns an instance of TextEncoder.', () => {
expect(window.TextEncoder).toBe(TextEncoder);
});
});

describe('get TextDecoder()', () => {
it('Returns an instance of TextDecoder.', () => {
expect(window.TextDecoder).toBe(TextDecoder);
});
});

describe('get location()', () => {
it('Returns an instance of Location', () => {
expect(window.location).toBeInstanceOf(Location);
Expand Down Expand Up @@ -489,7 +501,7 @@ describe('BrowserWindow', () => {
elementStyle.innerHTML = `
span {
border: 1px solid #000;
border-radius: 2px;
border-radius: 2px;
color: green;
cursor: default;
direction: ltr;
Expand Down Expand Up @@ -664,7 +676,7 @@ describe('BrowserWindow', () => {
--result1: var(--color1, var(--unknown, var(--unknown, green)));
--result2: var(--unknown, var(--color1, var(--unknown, green)));
--result3: var(--unknown, var(--unknown, var(--color1, green)));
--result4: var(--unknown, var(--unknown, var(--unknown, var(--unknown, white))));
--result5: var(--color1, var(--color2));
Expand Down Expand Up @@ -920,7 +932,7 @@ describe('BrowserWindow', () => {
span {
color: green;
}
:not {
color: red;
}
Expand Down

0 comments on commit 7914b54

Please sign in to comment.