summaryrefslogtreecommitdiff
path: root/cli/js/mixins/dom_iterable_test.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-03-10 01:06:47 +0100
committerGitHub <noreply@github.com>2020-03-10 01:06:47 +0100
commit68119e1d7ed23421ccdcba20532ebe9ae3df9f18 (patch)
tree455dd170024112e3388adc27ebebb119b0ecda38 /cli/js/mixins/dom_iterable_test.ts
parentdad8036766dca3417b79858b9a04d90447f88605 (diff)
reorg: move js runtime tests to cli/js/tests/ (#4250)
All Deno runtime test files were moved to cli/js/tests/ directory. It makes a clear distinction that cli/js/tests/ contains code that is run under Deno runtime as opposed to code in cli/js/ which is used to create bundle and snapshot with "deno_typescript".
Diffstat (limited to 'cli/js/mixins/dom_iterable_test.ts')
-rw-r--r--cli/js/mixins/dom_iterable_test.ts87
1 files changed, 0 insertions, 87 deletions
diff --git a/cli/js/mixins/dom_iterable_test.ts b/cli/js/mixins/dom_iterable_test.ts
deleted file mode 100644
index a1b8b5699..000000000
--- a/cli/js/mixins/dom_iterable_test.ts
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { unitTest, assert, assertEquals } from "../test_util.ts";
-
-// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
-function setup() {
- const dataSymbol = Symbol("data symbol");
- class Base {
- private [dataSymbol] = new Map<string, number>();
-
- constructor(
- data: Array<[string, number]> | IterableIterator<[string, number]>
- ) {
- for (const [key, value] of data) {
- this[dataSymbol].set(key, value);
- }
- }
- }
-
- return {
- Base,
- // This is using an internal API we don't want published as types, so having
- // to cast to any to "trick" TypeScript
- // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
- DomIterable: Deno[Deno.symbols.internal].DomIterableMixin(Base, dataSymbol)
- };
-}
-
-unitTest(function testDomIterable(): void {
- const { DomIterable, Base } = setup();
-
- const fixture: Array<[string, number]> = [
- ["foo", 1],
- ["bar", 2]
- ];
-
- const domIterable = new DomIterable(fixture);
-
- assertEquals(Array.from(domIterable.entries()), fixture);
- assertEquals(Array.from(domIterable.values()), [1, 2]);
- assertEquals(Array.from(domIterable.keys()), ["foo", "bar"]);
-
- let result: Array<[string, number]> = [];
- for (const [key, value] of domIterable) {
- assert(key != null);
- assert(value != null);
- result.push([key, value]);
- }
- assertEquals(fixture, result);
-
- result = [];
- const scope = {};
- function callback(
- this: typeof scope,
- value: number,
- key: string,
- parent: typeof domIterable
- ): void {
- assertEquals(parent, domIterable);
- assert(key != null);
- assert(value != null);
- assert(this === scope);
- result.push([key, value]);
- }
- domIterable.forEach(callback, scope);
- assertEquals(fixture, result);
-
- assertEquals(DomIterable.name, Base.name);
-});
-
-unitTest(function testDomIterableScope(): void {
- const { DomIterable } = setup();
-
- const domIterable = new DomIterable([["foo", 1]]);
-
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- function checkScope(thisArg: any, expected: any): void {
- function callback(this: typeof thisArg): void {
- assertEquals(this, expected);
- }
- domIterable.forEach(callback, thisArg);
- }
-
- checkScope(0, Object(0));
- checkScope("", Object(""));
- checkScope(null, window);
- checkScope(undefined, window);
-});