Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2021-10-21 16:07:35 +02:00
parent 447c514899
commit 7c5cf5a4a4
3 changed files with 126 additions and 1 deletions
+3 -1
View File
@@ -31,7 +31,9 @@
},
"dependencies": {},
"devDependencies": {
"@backstage/cli": "^0.7.11"
"@backstage/cli": "^0.7.11",
"@types/zen-observable": "^0.8.0",
"zen-observable": "^0.8.15"
},
"files": [
"dist"
+81
View File
@@ -0,0 +1,81 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { JsonPrimitive, JsonArray, JsonObject, JsonValue } from './json';
describe('json', () => {
it('JsonPrimitive', () => {
function isValid(..._v: JsonPrimitive[]) {}
isValid(1, 's', true, false, null);
// @ts-expect-error
const v1: JsonPrimitive = [];
// @ts-expect-error
const v2: JsonPrimitive = {};
expect(true).toBe(true);
});
it('JsonArray', () => {
function isValid(..._v: JsonArray[]) {}
isValid([], [1, 's', true, false, null, {}, []]);
// @ts-expect-error
const v1: JsonArray = 1;
// @ts-expect-error
const v2: JsonArray = 's';
// @ts-expect-error
const v3: JsonArray = true;
// @ts-expect-error
const v4: JsonArray = false;
// @ts-expect-error
const v5: JsonArray = null;
// @ts-expect-error
const v6: JsonArray = {};
expect(true).toBe(true);
});
it('JsonObject', () => {
function isValid(..._v: JsonObject[]) {}
isValid(
{},
{ v1: 1, v2: 's', v3: true, v4: false, v5: null, v6: {}, v7: [] },
);
// @ts-expect-error
const v1: JsonObject = 1;
// @ts-expect-error
const v2: JsonObject = 's';
// @ts-expect-error
const v3: JsonObject = true;
// @ts-expect-error
const v4: JsonObject = false;
// @ts-expect-error
const v5: JsonObject = null;
// @ts-expect-error
const v6: JsonObject = [];
expect(true).toBe(true);
});
it('JsonValue', () => {
function isValid(..._v: JsonValue[]) {}
isValid(1, 's', true, false, null, {}, []);
expect(true).toBe(true);
});
});
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import ZenObservable from 'zen-observable';
import { Observable, Observer, Subscription } from './observable';
describe('observable', () => {
it('works in conjunction with zen-observables', () => {
// Use ZenObservable as the concrete implementation, but use our types in
// all other possible places in the code
const observable: Observable<string> = new ZenObservable<string>(
(subscriber: Observer<string>) => {
subscriber.next!('a');
subscriber.error!(new Error('e'));
subscriber.complete!();
},
);
const subscription: Subscription = observable.subscribe(
_value => {},
_error => {},
() => {},
);
subscription.unsubscribe();
expect(true).toBe(true);
});
});