-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
TypeStorage-test.js
48 lines (39 loc) · 1.62 KB
/
TypeStorage-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* @flow strict */
import { TypeStorage } from '../TypeStorage';
import { GraphQLString } from '../graphql';
let typeStorage;
describe('typeStorage', () => {
beforeEach(() => {
typeStorage = new TypeStorage();
});
it('should be instance of Map', () => {
expect(typeStorage).toBeInstanceOf(TypeStorage);
});
it('should work `get`, `set`, `has`, `clear` methods and `size` property', () => {
expect(typeStorage.size).toEqual(0);
typeStorage.set('MyType', GraphQLString);
expect(typeStorage.get('MyType')).toEqual(GraphQLString);
expect(typeStorage.has('MyType')).toEqual(true);
expect(typeStorage.size).toEqual(1);
typeStorage.clear();
expect(typeStorage.size).toEqual(0);
});
describe('getOrSet() method', () => {
it('should return existed value', () => {
typeStorage.set('MyType', GraphQLString);
expect(typeStorage.getOrSet('MyType', () => ('SomeOtherType': any))).toEqual(GraphQLString);
});
it('should set new type as function and return type, if key not exists', () => {
expect(typeStorage.getOrSet('MyType', () => GraphQLString)).toEqual(GraphQLString);
expect(typeStorage.get('MyType')).toEqual(GraphQLString);
});
it('should set new type and return it, if key not exists', () => {
expect(typeStorage.getOrSet('MyType', GraphQLString)).toEqual(GraphQLString);
expect(typeStorage.get('MyType')).toEqual(GraphQLString);
});
it('should not set new value if it is empty', () => {
expect(typeStorage.getOrSet('MyType', () => (null: any))).toEqual(null);
expect(typeStorage.has('MyType')).toEqual(false);
});
});
});